RSelenium cannot access DOM

2019-05-30 01:29发布

问题:

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:

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:

  • WebDriver click() vs JavaScript click()