Home > OS >  RSelenium message:no such element: Unable to locate element
RSelenium message:no such element: Unable to locate element

Time:05-17

I intend to download and clean databases using RSelenium. I am able to open the link however I am having trouble downloading and opening the database. I believe the xpath is right but when I try to open I receive the following error

Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="ESTBAN_AGENCIA"]"}

My code is the following:

dir <- getwd()
file_path <- paste0(dir,"\\DataBase") %>% str_replace_all("/", "\\\\\\")

eCaps <- list(
  chromeOptions = 
    list(prefs = list('download.default_directory' = file_path))
)

system("taskkill /im java.exe /f", intern=FALSE, ignore.stdout=FALSE)
#Creating server
rD <-  rsDriver(browser = "chrome", 
                chromever = "101.0.4951.15",
                port = 4812L,
                extraCapabilities = eCaps)  

#Creating the driver to use R

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  browserName = "chrome",
  port = 4812L) 

#Open server
remDr$open()
#Navegating in the webpage of ESTABAN
remDr$navigate("https://www.bcb.gov.br/acessoinformacao/legado?url=https://www4.bcb.gov.br/fis/cosif/estban.asp")

##Download 
remDr$findElement(using ="xpath", '//*[@id="ESTBAN_AGENCIA"]/option[1]')

CodePudding user response:

The element you are trying to access is inside an iframe and you need switch that iframe first in order to access the element.

enter image description here

remDr$navigate("https://www.bcb.gov.br/acessoinformacao/legado?url=https://www4.bcb.gov.br/fis/cosif/estban.asp")

#Switch to Iframe
webElem <- remDr$findElement("css", "iframe#framelegado")
remDr$switchToFrame(webElem)

##Download 
remDr$findElement(using ="xpath", '//*[@id="ESTBAN_AGENCIA"]/option[1]')
  • Related