简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM