john
john

Reputation: 1036

Value not selected from dropdown

In the website I am trying to select "English" language from the dropdown shown in top in the website. I am able to open the dropdown but value ('English') is not selected from the dropdown. I am very close but it seems missing something simple.

library(RSelenium)
library(xml2)
library(rvest)

# Docker
shell('docker run -d -p 4445:4444 selenium/standalone-chrome')
remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost",
                                 port = 4445L,
                                 browserName = "chrome")
remDr$open()

# Website
remDr$navigate("https://www.idealista.com/venta-viviendas/madrid-madrid/")

# Change Language Selector
webElem <- remDr$findElement(using='class', 'lang-selector')
webElem$getElementAttribute("class")
webElem$clickElement()

# change to English
webElem1 <- remDr$findElement(using = 'xpath', "//span[contains(@class,'lang-selected') and contains(text(),'English')]")
webElem1$clickElement()

Upvotes: 0

Views: 50

Answers (1)

Amruta
Amruta

Reputation: 1166

Try this xpath

//*[@id='main-header']//a[@id='idioma-en']/span[normalize-space(contains(text(),'English'))]

Able to select English

Upvotes: 1

Related Questions