Finding element/elements using RSelenium

4k Views Asked by At

I am trying to find one singular element on this website using findElement

https://shiny.rstudio.com/gallery/datatables-options.html

For example "Display length".

Later I would like to find all elements using findElements. That is, "Display length", ..., "Function callback". Total of 5.

My attempt for just finding the first element (Display length):

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

My attemp on finding several elements:

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
1

There are 1 best solutions below

0
On BEST ANSWER
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"