With the most recent update on chrome browser and chromedriver I've started getting staleElementReferenceException in WebDriver.
This should have been handled by my custom Wait method, but in some (rare cases) it still happens.
Here is my wait method:
public static WebElement getLoadedElement(String selector){
final Wait<WebDriver> longWait =
new FluentWait<WebDriver>(Driver.getDriver()).withTimeout(15, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
final WebElement element = longWait.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(final WebDriver driver) {
return driver.findElement(By.xpath(selector));
}
});
return element;
}
Is there another way of doing this without having to add a wrapper around all of the basic WebDriver actions (such as .click(), .getText(), etc.) ?
The only other solution I've found is by creating a counter and attempting to find the element over and over again at set intervals (0.5 seconds) but for this I'm having trouble catching multiple exceptions at the end of the timeout(counter).
Checking for .isClickable() is also not an option since I don't want to have to click on some elements in order to find them.
Any other ideas? I'm sure someone knows a better solution!