1

我在Stockpair 网站上使用 Selenium

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 没有改变,加载页面后元素仍然存在。

会不会有其他原因?

4

1 回答 1

4

这是一个非常动态的站点,它会定期更新更改 DOM。

通过 JavaScript单击元素:

s$executeScript("arguments[0].click();", list(dir))

另见:

于 2016-01-21T13:49:59.437 回答