【问题标题】:RSelenium cannot access DOMRSelenium 无法访问 DOM
【发布时间】:2016-01-21 13:35:12
【问题描述】:

我在 Stockpair Website 上使用 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 通过异步过程发生变化,就会发生这种情况。但是,我测试了运行 chrome.exe 可见的 Selenium,并且 DOM 没有改变,加载页面后元素仍然存在。

还有其他原因吗?

【问题讨论】:

    标签: r selenium selenium-chromedriver rselenium


    【解决方案1】:

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

    点击元素通过JavaScript

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

    另见:

    【讨论】:

    • 谢谢,但使用您的代码我得到错误:摘要:未知错误详细信息:处理命令时发生未知的服务器端错误。类:org.openqa.selenium.remote.JsonException 另外:有28个警告(使用warnings()查看)
    • 这行得通:s$executeScript("$('div.stockSelectionButton.left').click();", args = list())
    • @user670186 啊,忘记调用列表了,请重新测试。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2020-07-25
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2020-02-07
    • 2014-03-08
    • 2012-07-31
    相关资源
    最近更新 更多