Skip to content

Commit 1b7aa8d

Browse files
authored
Merge pull request #67 from AutomateThePlanet/navramov_MM
Handle stale element reference exception
2 parents ba99eb8 + 25f71b3 commit 1b7aa8d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ public <ComponentT extends WebComponent> ComponentT as(Class<ComponentT> compone
118118

119119
public WebElement getWrappedElement() {
120120
try {
121-
wrappedElement.isDisplayed(); // checking if getting property throws exception
122-
return wrappedElement;
123-
} catch (StaleElementReferenceException | NoSuchElementException | NullPointerException | ScriptTimeoutException ex ) {
121+
if(wrappedElement != null) {
122+
wrappedElement.isDisplayed(); // checking if getting property throws exception
123+
return wrappedElement;
124+
} else {
125+
return findElement();
126+
}
127+
} catch (Exception ex ) {
124128
return findElement();
125129
}
126130
}

bellatrix.web/src/main/java/solutions/bellatrix/web/waitstrategies/ToExistWaitStrategy.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
package solutions.bellatrix.web.waitstrategies;
1515

16-
import org.openqa.selenium.By;
17-
import org.openqa.selenium.NoSuchElementException;
18-
import org.openqa.selenium.SearchContext;
16+
import org.openqa.selenium.*;
1917
import solutions.bellatrix.core.configuration.ConfigurationService;
2018
import solutions.bellatrix.web.configuration.WebSettings;
2119

@@ -42,7 +40,7 @@ private boolean elementExists(SearchContext searchContext, By by) {
4240
try {
4341
var element = findElement(searchContext, by);
4442
return element != null;
45-
} catch (NoSuchElementException e) {
43+
} catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException e) {
4644
return false;
4745
}
4846
}

0 commit comments

Comments
 (0)