I'm using the RSelenium package in R to do webscraping. Sometimes after loading a webpage, it's required to check if an object is visible in a webpage or not. For example:
library(RSelenium)
#open a browser
RSelenium::startServer()
remDr <- remoteDriver$new()
remDr <- remoteDriver(remoteServerAddr = "localhost"
, port = 4444
, browserName = "firefox")
remDr$open()
remDr$navigate("https://www.google.com")
#xpath for Google logo
x_path="/html/body/div/div[5]/span/center/div[1]/img"
I need to do something like this:
if (exist(remDr$findElement(using='xpath',x_path))){
print("Logo Exists")
}
My question is what function should I use for "exist"? The above code does not work it's just a pseudo code. I have also found a code which works for checking objects using their "id", here it is:
remDr$executeScript("return document.getElementById('hplogo').hidden;", args = list())
The above code works for only "id", how should I do the same using "xpath"? Thanks