Skip to content

Commit

Permalink
Merge pull request #270 from Xceptance/#263-bug-stale-element-excepti…
Browse files Browse the repository at this point in the history
…on-log

[#263] Bug: StaleElementException Log
  • Loading branch information
wurzelkuchen authored Jul 15, 2024
2 parents f87d1b2 + bdd871f commit 7608631
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,82 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.WebDriverListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xceptance.neodymium.util.DebugUtils;
import com.xceptance.neodymium.util.Neodymium;
import com.xceptance.neodymium.util.SelenideAddons;

public class NeodymiumWebDriverListener implements WebDriverListener
{
private static final Logger LOGGER = LoggerFactory.getLogger(NeodymiumWebDriverListener.class);

@Override
public void beforeFindElement(WebDriver driver, By by)
{
DebugUtils.injectHighlightingJs();
DebugUtils.highlightAllElements(by, driver);
try
{
if (Neodymium.configuration().debuggingHighlightSelectedElements())
{
DebugUtils.injectHighlightingJs();
DebugUtils.highlightAllElements(by, driver);
}
}
catch (Throwable e)
{
LOGGER.warn("Could not find element to highlight. If you don't need the highlight, please set the neodymium.debugUtils.highlight to false", e);
}
}

@Override
public void beforeFindElements(WebDriver driver, By by)
{
DebugUtils.injectHighlightingJs();
DebugUtils.highlightAllElements(by, driver);
try
{
if (Neodymium.configuration().debuggingHighlightSelectedElements())
{
DebugUtils.injectHighlightingJs();
DebugUtils.highlightAllElements(by, driver);
}
}
catch (Throwable e)
{
LOGGER.warn("Could not find element to highlight. If you don't need the highlight, please set the neodymium.debugUtils.highlight to false", e);
}
}

@Override
public void beforeFindElement(WebElement element, By locator)
{
DebugUtils.injectHighlightingJs();
SelenideAddons.$safe(() -> DebugUtils.highlightAllElements(element.findElements(locator), Neodymium.getDriver()));
try
{
if (Neodymium.configuration().debuggingHighlightSelectedElements())
{
DebugUtils.injectHighlightingJs();
SelenideAddons.$safe(() -> DebugUtils.highlightAllElements(element.findElements(locator), Neodymium.getDriver()));
}
}
catch (Throwable e)
{
LOGGER.warn("Could not find element to highlight. If you don't need the highlight, please set the neodymium.debugUtils.highlight to false", e);
}
}

@Override
public void beforeFindElements(WebElement element, By locator)
{
DebugUtils.injectHighlightingJs();
SelenideAddons.$safe(() -> DebugUtils.highlightAllElements(element.findElements(locator), Neodymium.getDriver()));
try
{
if (Neodymium.configuration().debuggingHighlightSelectedElements())
{
DebugUtils.injectHighlightingJs();
SelenideAddons.$safe(() -> DebugUtils.highlightAllElements(element.findElements(locator), Neodymium.getDriver()));
}
}
catch (Throwable e)
{
LOGGER.warn("Could not find element to highlight. If you don't need the highlight, please set the neodymium.debugUtils.highlight to false", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ElementsCollection get()
}
catch (final Throwable t)
{
if (isThrowableCausedBy(t, StaleElementReferenceException.class, SERE))
if (t instanceof StaleElementReferenceException || isThrowableCausedBy(t, StaleElementReferenceException.class, SERE))
{
retryCounter++;
if (retryCounter > maxRetryCount)
Expand Down

0 comments on commit 7608631

Please sign in to comment.