RSelenium cannot access DOM

2019-05-30 01:52发布

I am using Selenium on Stockpair Website

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()

I get the error

Error:   Summary: StaleElementReference
     Detail: An element command failed because the referenced element is no longer attached to the DOM.
     class: org.openqa.selenium.StaleElementReferenceException

I researched that it happens if the DOM changes by an asynchronous process. However, I tested with Selenium running chrome.exe visible and the DOM doesnt change and th element is still there after loading the page.

Can there be other causes?

1条回答
别忘想泡老子
2楼-- · 2019-05-30 02:18

This is quite a dynamic site with periodical updates which change the DOM.

Click the element via JavaScript:

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

Also see:

查看更多
登录 后发表回答