I am trying to scrape a link with Rselenium. Sometimes--only sometimes and this is not replicable (cause when I re-run the code, the problem disappear)--the programme gives me an error as follows:
Error: Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
Further Details: run errorDetails method
I think this is because I clicked on a web element and the DOM is somehow modified after a click (see this answer: RSelenium throwing StaleElementReference error). In this case, my code is to click on all the "expand" arrow of a weblink so show the full text. But the click under concern here is wrapped in a sapply function as follows, so I cannot relocate the web element every time:
arrow = remDr$findElements(using = 'class', value = "WB_text_opt") #locate the arrows
sapply(arrow, function(x){
Sys.sleep(0.15)
x$clickElement()
}) # click on them
remDr$findElement('css', 'html')$sendKeysToElement(list(key = "end")) # scroll the webpage down