0

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]])
BrianLang
  • 831
  • 4
  • 14
John_Ruf
  • 43
  • 1
  • 5
  • What is the error ? – Sureshmani Kalirajan Oct 07 '20 at 12:47
  • The error is "Error: attempt to apply non-function" since checkbox isn't an object containing active binding. – John_Ruf Oct 07 '20 at 13:47
  • findElements returns a collection of element (i.e list). If you need to specific elements within it, you either have to iterate through the list using for loop or use findElement method to directly locate the element. – Sureshmani Kalirajan Oct 07 '20 at 14:42
  • How would you iterate through the list using a for loop? I'm confused since nothing in the list contains active binding. As far as I know (which is not at all) the element I'm looking for can't be selected with the findElement method, as the html code for the element isn't unique and find element only selects the first element found, so the only way I've been able to locate it is with the findElements method. – John_Ruf Oct 07 '20 at 15:03
  • It is possible to find the element directly using xpaths.I will post an answer with possible solution. – Sureshmani Kalirajan Oct 07 '20 at 16:05

1 Answers1

0

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()
Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18