RSelenium在具有下拉列表的页面上找不到元素

RSelenium在具有下拉列表的页面上找不到元素,r,rselenium,R,Rselenium,我试图从使用下拉列表的表中提取一些数据。表格为“GIC选项”。“期限”为“中期”,而“利息类型”为“复合” 看着如此的答案,我试着: library(RSelenium) remDr <- remoteDriver(port = 4445L) remDr$navigate("https://www.nbc.ca/personal/savings-investments/gic/non-redeemable.html") webElem <- remDr$findE

我试图从使用下拉列表的表中提取一些数据。表格为“GIC选项”。“期限”为“中期”,而“利息类型”为“复合”

看着如此的答案,我试着:

library(RSelenium)
remDr <- remoteDriver(port = 4445L)
remDr$navigate("https://www.nbc.ca/personal/savings-investments/gic/non-redeemable.html")
webElem <- remDr$findElement(using = "xpath", '//*[@class="ft2-dropdown-list-element"]/option[@value="Mid-Term"]')
库(RSelenium)
在我的解决方案下方重新绘制

library(RSelenium)
driver <- rsDriver(browser=c("firefox"),port = 4445L)
remote_driver <- driver[["client"]]  
remote_driver$navigate("https://www.nbc.ca/personal/savings-investments/gic/non-redeemable.html")

#Active the box by a click
remote_driver$findElement(using = "css selector", '.ft2-dropdown-btn-label')$clickElement()

#Now you can choose what you need
remote_driver$findElement(using = "xpath", '//*[@id="ft2"]/div[2]/div/ul/li[3]/a')$clickElement()

#All
//*[@id="ft2"]/div[2]/div/ul/li[1]/a
#Short term
//*[@id="ft2"]/div[2]/div/ul/li[2]/a
#Mid term
//*[@id="ft2"]/div[2]/div/ul/li[3]/a
#Long term
//*[@id="ft2"]/div[2]/div/ul/li[4]/a

#To scrape the value of the table, below a possible solution.
webElem <- remote_driver$findElement(using = "css selector", 'div.table-wrapper:nth-child(4) > table:nth-child(1)')
webElem$getElementText()
库(RSelenium)

驱动程序您是如何派生这些XPath的,//*[@id=“ft2”]/div[2]/div/ul/li[1]/a等。单击列表后,我派生了它。
library(RSelenium)
driver <- rsDriver(browser=c("firefox"),port = 4445L)
remote_driver <- driver[["client"]]  
remote_driver$navigate("https://www.nbc.ca/personal/savings-investments/gic/non-redeemable.html")

#Active the box by a click
remote_driver$findElement(using = "css selector", '.ft2-dropdown-btn-label')$clickElement()

#Now you can choose what you need
remote_driver$findElement(using = "xpath", '//*[@id="ft2"]/div[2]/div/ul/li[3]/a')$clickElement()

#All
//*[@id="ft2"]/div[2]/div/ul/li[1]/a
#Short term
//*[@id="ft2"]/div[2]/div/ul/li[2]/a
#Mid term
//*[@id="ft2"]/div[2]/div/ul/li[3]/a
#Long term
//*[@id="ft2"]/div[2]/div/ul/li[4]/a

#To scrape the value of the table, below a possible solution.
webElem <- remote_driver$findElement(using = "css selector", 'div.table-wrapper:nth-child(4) > table:nth-child(1)')
webElem$getElementText()