2

I am trying to use clickElements() from the RSelenium package in order to drop down all of the downwards facing arrows in the "distrito" dropdown panel. I can do it for one of the dropdowns but I want to do it for all of them.

How can I click all of the dropdown items?

library(RSelenium)

rD <- rsDriver(browser="firefox", port=4536L)
remDr <- rD[["client"]]
url2 = "https://www.fotocasa.es/es/comprar/viviendas/barcelona-capital/todas-las-zonas/l"
remDr$navigate(url2)
remDr$maxWindowSize()

# accept cookies
remDr$findElement(using = "xpath",'/html/body/div[1]/div[4]/div/div/div/footer/div/button[2]')$clickElement()
#click on Distrito
remDr$findElement(using = "xpath", '/html/body/div[1]/div[2]/div[1]/div[3]/div/div[1]/div')$clickElement()

remDr$findElement(using = "class name", 'sui-MoleculeCheckboxField-toggleIcon')$clickElement()

1 Answer 1

2

findElements() creates a list of all webElements that were found. Therefore, you cannot use clickElement() on this list but you need to make a loop, like below:

library(RSelenium)

rD <- rsDriver(browser="firefox", port=4536L)
remDr <- rD[["client"]]
url2 = "https://www.fotocasa.es/es/comprar/viviendas/barcelona-capital/todas-las-zonas/l"
remDr$navigate(url2)
remDr$maxWindowSize()

# accept cookies
remDr$findElement(using = "xpath",'/html/body/div[1]/div[4]/div/div/div/footer/div/button[2]')$clickElement()

# click on Distrito
remDr$findElement(using = "class",'re-GeographicSearchNext')$clickElement()

# Find all checkboxes
checkboxes <- remDr$findElements(using = "class name", 're-GeographicSearchNext-checkboxItem')

class(checkboxes)
# [1] "list"

length(checkboxes)
# 10

# Loop for each checkbox
for (i in seq_along(checkboxes)) {
  checkboxes[[i]]$clickElement()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.