我正在尝试使用findElement
https://shiny.rstudio.com/gallery/datatables-options.html
例如“显示长度”。
稍后我想使用findElements
查找所有元素。即,“显示长度”,......,“函数回调”。总共5个。
我尝试找到第一个元素(显示长度):
remDr$navigate("https://shiny.rstudio.com/gallery/datatables-options.html")
elems <- remDr$findElement("css selector", "#showcase-app-container > nav > div > ul > li.active > a")
# Unable to locate element
elems <- remDr$findElement("xpath", "//*[@id='showcase-app-container']/nav/div/ul/li[1]/a")
# Unable to to locate element
我试图找到几个元素:
elems <- remDr$findElements("class", "nav navbar-nav")
# Invalid or does not result in a WebElement
elems <- remDr$findElements("css selector", "#showcase-app-container > nav > div > ul")
# list of 0
elems <- remDr$findElements("xpath", "//*[@id='showcase-app-container']/nav/div/ul")
# list of 0
答案 0 :(得分:5)
remDr$navigate("https://shiny.rstudio.com/gallery/datatables-options.html")
# htmlParse(remDr$getPageSource()[[1]]) to first the frames (only 1)
webElems <- remDr$findElements("css selector", "iframe")
remDr$switchToFrame(webElems[[1]])
elems <- remDr$findElements("css selector", "#showcase-app-container > nav > div > ul li")
unlist(lapply(elems, function(x) x$getElementText()))
# "Display length" "Length menu" "No pagination" "No filtering" "Function callback"