s = remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "chrome")
s$open()
url <- "https://www.stockpair.com/sp#trading/page"
s$navigate(url)
dir <- s$findElement("css selector", "div.stockSelectionButton.left")
dir$clickElement()
我收到错误
Error: Summary: StaleElementReference
Detail: An element command failed because the referenced element is no longer attached to the DOM.
class: org.openqa.selenium.StaleElementReferenceException
我研究过,如果DOM通过异步进程发生更改,就会发生这种情况。但是,我测试了Selenium运行chrome.exe可见,DOM没有改变,加载页面后元素仍然存在。
还有其他原因吗?
答案 0 :(得分:3)
这是一个非常动态的网站,定期更新可以更改DOM。
点击元素通过JavaScript :
s$executeScript("arguments[0].click();", list(dir))
另见: