Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click on cross domain iframe element using Rselenium

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?

like image 892
Mislav Avatar asked Mar 10 '23 08:03

Mislav


1 Answers

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']")
like image 136
jdharrison Avatar answered Mar 15 '23 12:03

jdharrison