单击使用Rselenium包含javascript的href [英] click href that contain javascript using Rselenium

查看:140
本文介绍了单击使用Rselenium包含javascript的href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R,版本3.3.2.我正在尝试从此网站上抓取一些数据: http://www.dziv.hr/en/e-services/on-line-database-search/patents/

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

我正在使用Rselenium,我的代码如下:

I am using Rselenium and my code looks like this:

webElem <- remDr$findElements("css", "iframe")
remDr$switchToFrame(webElem[[1]])
webel <- remDr$findElement(using = "xpath", "//input[@id = 'TB1']")$sendKeysToElement(list(as.character("*"), key = "enter"))
Sys.sleep(2)
windows_handles <- remDr$getWindowHandles()
Sys.sleep(1)
remDr$switchToWindow(windows_handles[[1]][[2]])

如您所见,在第三行出现新窗口后,我切换到该新窗口.在这个新窗口中,我想单击页面底部的第二页,然后单击3,依此类推.我尝试了几种解决方案,例如:

As you can see after third line new windows appear, and I switch to this new window. On this new window, I would like to click on second page on bottom of the page, then 3 and so on. I have tried several solutions, for example:

remDr$findElement(using = "xpath", "//a[contains(text(),'2')]")$clickElement() 
remDr$findElement(using = "xpath", "//a[@style = 'color:#333333;']")$clickElement()
remDr$findElement(using = "xpath", "/html/body/form/div[3]/div[1]/div/table/tbody/tr[27]/td/table/tbody/tr/td[2]/a[@href]")$clickElement()

此解决方案均无效.我认为这是因为href中的javascript?如何执行此javascript并继续第二页?我知道executeScript()函数,但不确定如何使用.

Non of this solutions works. I think this is because of the javascript in href? How can I execute this javascript and continue on second page? I know for executeScript() function, but not sure how to use it.

推荐答案

jdharrison回答了这个问题:

jdharrison answeres the question:

您可以使用remDr$executeScript("__doPostBack('GVRezultati','Page$2');")等选择页面...

You can select the pages using remDr$executeScript("__doPostBack('GVRezultati','Page$2');") etc...

这篇关于单击使用Rselenium包含javascript的href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆