Skip to content

StaleElementReference enhancements #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import solutions.bellatrix.core.plugins.EventListener;
import solutions.bellatrix.core.plugins.Plugin;
import solutions.bellatrix.core.plugins.TestResult;
import solutions.bellatrix.core.plugins.TimeRecord;

import java.lang.reflect.Method;
import java.nio.file.Paths;
Expand All @@ -37,7 +38,7 @@ public ScreenshotPlugin(boolean isEnabled) {

@Override
@SneakyThrows
public void postAfterTest(TestResult testResult, Method memberInfo, Throwable failedTestException) {
public void preAfterTest(TestResult testResult, TimeRecord timeRecord, Method memberInfo) {
if (!isEnabled || testResult == TestResult.SUCCESS)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ public WebElement getWrappedElement() {
} else {
return findElement();
}
} catch (Exception ex ) {
} catch (ElementNotInteractableException ex ) {
scrollToVisible();
return findElement();
} catch (StaleElementReferenceException ex ) {
return findElement();
} catch (WebDriverException ex ) {
toExist().waitToBe();
return wrappedElement;
}
}

Expand Down Expand Up @@ -844,7 +850,7 @@ private boolean inShadowContext() {
}

public WebElement findElement() {
if (waitStrategies.size() == 0) {
if (waitStrategies.isEmpty()) {
waitStrategies.add(Wait.to().exist(webSettings.getTimeoutSettings().getElementWaitTimeout(), webSettings.getTimeoutSettings().getSleepInterval()));
}

Expand Down Expand Up @@ -893,7 +899,8 @@ private void clickInternal() {
try {
wait.until(x -> tryClick());
} catch (TimeoutException e) {
toBeVisible().toBeClickable().findElement().click();
Log.info("Click has timed out. Trying with JS click()...");
javaScriptService.execute("arguments[0].click()", findElement());
}
}

Expand All @@ -902,9 +909,15 @@ private boolean tryClick() {
toBeVisible().toBeClickable().findElement().click();
return true;
} catch (ElementNotInteractableException e) {
Log.error("ElementNotInteractableException found - retrying with scroll.. ");
scrollToVisible();
return false;
} catch (StaleElementReferenceException e) {
Log.error("StaleElementReference Exception found - retrying with a new Find... ");
findElement();
return false;
} catch (WebDriverException e) {
toBeVisible().toBeClickable().waitToBe();
Log.error("WebDriverException found - trying again... ");
return false;
}
}
Expand Down Expand Up @@ -1291,6 +1304,9 @@ private void scrollToVisible(WebElement wrappedElement, boolean shouldWait, Scro
public boolean isVisible() {
try {
return getWrappedElement().isDisplayed();
} catch (StaleElementReferenceException e) {
wrappedElement = findElement();
return false;
} catch (NotFoundException e) {
return false;
}
Expand Down