How to utilize an element found via the find "findelements" command in Rselenium?

264 Views Asked by At

I'm trying to select a certain checkbox using the link below. I've managed to find the checkbox using the findelements command, however the problem is that I can't actually use the elements I found with the findelements command to click on an element. The problem seems to be that the findelements command outputs a list which is unusable if you unlist it as a character, as it loses its "object containing active binding" schtick.

I don't really know what to make of this and how to solve it, but it should be relatively easy, I can't imagine that it would be impossible to interact with an element found in a findelements list, but every attempt, including something as simple as "elements[4]" doesn't seem to work.

remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost",
                                 port = 4445L,
                                 browserName = "chrome")
remDr$open()
remDr$navigate("http://chicagodemocracy.org/ChooseElection.jsp")
remDr$screenshot(display = TRUE)

elements<- remDr$findElements(using = 'name', "office")
checkbox<-elements[4]
checkbox$clickElement()

remDr$screenshot(display = TRUE)
html <- xml2::read_html(remDr$getPageSource()[[1]])
1

There are 1 best solutions below

1
On

Try using xpath to find the elements directly. You can the 'value' depends on which checkbox you like to select

checkbox<- remDr$findElement(using = 'xpath', "//li/input[@value='Alderman']")

checkbox$clickElement()