【发布时间】:2020-04-22 02:48:41
【问题描述】:
我正在尝试获取与 Rselenium 的链接。有时——只是有时,这是不可复制的(因为当我重新运行代码时,问题消失了)——程序给我一个错误如下:
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
我认为这是因为我单击了一个 Web 元素,并且单击后 DOM 以某种方式被修改(请参阅此答案:RSelenium throwing StaleElementReference error)。在这种情况下,我的代码是单击网络链接的所有“展开”箭头,以便显示全文。但是这里关注的点击被包裹在一个 sapply 函数中,如下所示,所以我不能每次都重新定位 web 元素:
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
【问题讨论】:
标签: r selenium web-scraping