I am testing the newly built framework, and am often encountering org.openqa.selenium.StaleElementReferenceException while working in the Chrome browser. Could there be an issue with the framework design?
There are no issues when I run my tests in other browsers. I tried many types of custom waits that catch the StaleElementReferenceException and then loops to find the element, but no luck.
Has anyone faced a similar issue and found a solution?
Chrome version: 38.0.2125.111
Selenium version: 2.43.1
public WebElement waitTill(By by){
WebElement ele = null;
for(int i=0; i<15; i++){
try {
ele = driver.findElement(by);
if(ele==null)
Thread.sleep(2000); //in last attempt used thread...we wont use this in actual practice
else
break;
} catch (NoSuchElementException | InterruptedException e) {
System.out.println(e.getMessage());
}
}
return ele;
}
public WebElement getElement(String loc) {
String locator = initUtils.ORProp.getProperty(loc);
WebElement element = null;
try{
By by = getBy(locator);
element = waitTill(by);
}catch(NoSuchElementException e){
System.out.println(e.getMessage());
}catch(StaleElementReferenceException e){
By by = getBy(locator);
element = waitTill(by);
}
return element;
}