RSelenium message:no 这样的元素:无法定位元素

RSelenium message:no such element: Unable to locate element

我打算使用 RSelenium 下载和清理数据库。我可以打开 link 但是我在下载和打开数据库时遇到问题。我相信 xpath 是正确的,但是当我尝试打开时收到以下错误

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

我的代码如下:

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:%2F%2Fwww4.bcb.gov.br%2Ffis%2Fcosif%2Festban.asp")

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

您尝试访问的元素在 iframe 中,您需要先切换 iframe 才能访问该元素。

remDr$navigate("https://www.bcb.gov.br/acessoinformacao/legado?url=https:%2F%2Fwww4.bcb.gov.br%2Ffis%2Fcosif%2Festban.asp")

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

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