Reputation: 2083
My example is:
library(RSelenium)
remDr <- remoteDriver()
remDr$open(silent = TRUE)
remDr$navigate("http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/")
remDr$findElement("id", "three")$click()
Which doesn't seem to work. Can someone help with what's wrong?
Upvotes: 3
Views: 1695
Reputation: 350
I don't know why but the things that I found over various forums didn't work for me.
webElem <- remDr$findElement("id", "three")
webElem$clickElement()
webElem <- remDr$findElement("id", "three")
webElem$sendKeysToElement(list(key="enter"))
remDr$executeScript("document.getElementById('three').click()")
The last one somehow worked for me when the first two didn't work for me.
Upvotes: 1
Reputation: 30425
You are on the right track. Looking at ?remoteDriver
the click
method is described as:
click(buttonId = 0)
Click any mouse button (at the coordinates set by the last mouseMoveToLocation() command). buttonId - any one of 'LEFT'/0 'MIDDLE'/1 'RIGHT'/2. Defaults to 'LEFT'
This method is for clicking at a location on the screen. Your code can be changed slightly so that the findElement
method result is assigned.
library(RSelenium)
# startServer() # start Selenium Server if needed
remDr <- remoteDriver()
remDr$open(silent = TRUE)
remDr$navigate("http://www.nngroup.com/articles/checkboxes-vs-radio-buttons/")
webElem <- remDr$findElement("id", "three")
> class(webElem)
[1] "webElement"
attr(,"package")
[1] "RSelenium"
Looking at the documentation for the webElement
class there is a method clickElement
:
webElem$clickElement()
Using this method should produce the required result.
Upvotes: 2