2016-01-21 63 views
1

我使用硒对Stockpair WebsiteRSelenium不能访问DOM

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变化。然而,我使用运行chrome.exe的Selenium进行了测试,并且DOM不会更改,并且在加载页面后th元素仍然存在。

会有其他原因吗?

回答

2

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

通过JavaScript单击元素

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

另见:

+0

感谢,但你的代码,我得到错误:摘要:不明错误 \t详细信息:处理命令时发生未知的服务器端错误。 \t class:org.openqa.selenium.remote.JsonException 此外:有28个警告(使用警告()来查看它们) – user670186

+0

这个工程:s $ executeScript(“$('div.stockSelectionButton.left')。点击();“,args = list()) – user670186

+0

@ user670186啊,忘记打电话了,请重新测试。谢谢。 – alecxe