使用Rselenium移至新的弹出窗口

时间:2018-01-30 13:57:21

标签: r web-scraping httr rselenium

我有以下Rselenum代码:

library(RSelenium)

remDr <- remoteDriver(remoteServerAddr = "192.168.99.100", port = 4445L, browserName = "chrome")
remDr$open()

# Simulate browser session and fill out form
remDr$navigate("https://oss.uredjenazemlja.hr/public/lrServices.jsp?action=publicLdbExtract")

remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-29']/input")$sendKeysToElement(list("Beli Manastir", key = "enter"))
Sys.sleep(1L)
remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-30']/input")$clickElement()
Sys.sleep(1L)
remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-30']/input")$sendKeysToElement(list("Baranjsko", key = "enter"))
Sys.sleep(1L)
remDr$findElement(using = "id", 
                  "x-auto-32")$sendKeysToElement(list("1"))
Sys.sleep(1L)
remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-33']/input")$clickElement()
Sys.sleep(1L)
remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-35']/div[2]")$clickElement()
Sys.sleep(1L)
remDr$findElement(using = "xpath", 
                  "//*[@id='x-auto-14']/tbody/tr/td[2]/em/button")$clickElement()

正如你可以看到新的&#34;窗口&#34;弹出。如果我尝试在新窗口中选择任何元素但它返回并出错。我怎么能下载验证码图片或怀疑文本框中的东西?我试过Windows处理程序,但它不是一个新窗口。

编辑:

我在几个地方发现我应该使用javascript来点击隐藏的元素。我试过了:

script <- "return document.getElementById('x-auto-135').hidden;"
remDr$executeScript(script, args = list())

但是收到错误:

Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: java.lang.NullPointerException
     Further Details: run errorDetails method

1 个答案:

答案 0 :(得分:0)

我终于找到了解决方案:

D2D1_COLORMATRIX_PROP_COLOR_MATRIX