A
A
Alexey FRZ2020-03-01 22:50:57
Java
Alexey FRZ, 2020-03-01 22:50:57

Selenium webDriver: StaleElementReferenceException. How to get rid?

Get a list of required web elements

List<WebElement> temp = driver.findElements(By.cssSelector("span.selection-link"));

Next, I want to get attribute values ​​​​from the list, while I do this, a StaleElementReferenceException falls out. As I understand it, communication with web elements is lost and this exception is thrown. QUESTIONS:

1) I saved the parsed web elements in a sheet, what does webDriver have to do with it? I parsed and put in a List, then I work with it, what is the connection of the List in which I saved what I parsed and the webDriver?
2) How can you save the parsed web elements and work with them after driver.quit?
In the context of my task, this List in web elements will need to be processed several times (for example, to get the values ​​\u200b\u200bof attributes and tag content)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergey, 2020-03-02
kuzmin @sergueik

save parsed web elements and work with them after driver.quit cannot be
processed while lukewarm
when accessing some method it has a check that it is still rendered by
the browser
This essentially determines whether or not the element is still attached to the DOM.
No ? sorry -
@throws StaleElementReferenceException If the element no
* longer exists as initially defined

S
sviato_slav, 2020-03-02
@sviato_slav

You can do the following:
save the entire page to a string:

String html = driver.findElement(By.tagName("html")).getAttribute("innerHTML")

And then work with the string by other means: Jsoup, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question