Click on cross domain iframe element using Rselenium

1.5k views Asked by At

I am using R, version 3.3.2. Using Rselenium package, I am trying to scrap some data from this website: http://www.dziv.hr/en/e-services/on-line-database-search/patents/

I am using Rselenium and my code looks like this:

selServ <- RSelenium::startServer(javaargs = c("-Dwebdriver.gecko.driver=\"C:/Users/Mislav/Documents/geckodriver.exe\""))
remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
remDr$open()
Sys.sleep(2)

# Simulate browser session and fill out form
remDr$navigate("http://www.dziv.hr/hr/e-usluge/pretrazivanje-baza-podataka/patent/")

This doesn't work:

webel <- remDr$findElement(using = "xpath", "/input[@id = 'TB1']")

Then I wanted to swith to iframe using switchToFrame() function, but the iframe does not contain id.

Then I have tr to use index: webel <- remDr$switchToFrame(1) but this just return NULL

Also, I recognized, iframe has different domain.

Is it possible to svrap data from this web site?

1

There are 1 answers

0
jdharrison On BEST ANSWER

You can just select the first iframe and pass it to the switchToFrame method:

webElem <- remDr$findElements("css", "iframe")
remDr$switchToFrame(webElem[[1]])
webel <- remDr$findElement(using = "xpath", "//input[@id = 'TB1']")