Hi,
Suddenly i have starting hitting stale element exception for below scenario:
1. Getting element in list :
List<WebElement> list = driver.findElements(By.cssSelecto("ul#doc-list a.text-title"));
It return list of 4 elements.
2. getText() from list elements and add to set.
Set<String> set = new HashSet<String>();
for (WebElement we : list) {
set.add(we.getText()); // i am hitting stale element on this line always.
}
Solutions tried :
1. Load list again before getting text
for (WebElement we : list) {
list = driver.findElements(By.cssSelecto("ul#doc-list a.text-title"));
set.add(we.getText());
}
2. get list element in loop in case list is not loaded completely.
for(int i=0;i<5;i++)
{
list = driver.findElements(By.cssSelecto("ul#doc-list a.text-title"));
}
3. Add text from list element in another list, then add to set.
List<String> text = new ArrayList();
for(WebElement s : list)
{
li.add(s.getText();
}
Nothing worked at all. This stale element exception is not consistent, 2 times it runs successfully next time it hits error. This exception occurs only running in CI, on local i never hot it so i am not bale to debug it. It all started after upgrading to chrome 66.
Anyone has any solution to this, please advice same.
Thanks !!