Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查RSelenium中的对话框_R_Selenium Webdriver - Fatal编程技术网

检查RSelenium中的对话框

检查RSelenium中的对话框,r,selenium-webdriver,R,Selenium Webdriver,我正在使用RSelenium访问工资页面。如果发生错误,页面上偶尔会显示对话框。检查对话框是否显示并检索其内容(如果存在)的正确方法是什么 这个问题实际上更一般:很多函数,比如findElement在找不到元素时抛出异常。检查元素的最佳方法是什么?为每个命令单独设置一个tryCatch似乎很麻烦。您选择的示例是一个带有框架的页面,因此首先需要将正确的框架切换到: appURL <- "http://www.w3schools.com/js/tryit.asp?filename=tryjs_

我正在使用RSelenium访问工资页面。如果发生错误,页面上偶尔会显示对话框。检查对话框是否显示并检索其内容(如果存在)的正确方法是什么


这个问题实际上更一般:很多函数,比如
findElement
在找不到元素时抛出异常。检查元素的最佳方法是什么?为每个命令单独设置一个
tryCatch
似乎很麻烦。

您选择的示例是一个带有框架的页面,因此首先需要将正确的框架切换到:

appURL <- "http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm"
library(RSelenium)
RSelenium::startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate(appURL)
# This page has frames
remDr$switchToFrame(remDr$findElement("id", "iframeResult"))
webElem <- remDr$findElement("css", "button")
# visually confirm element
webElem$highlightElement()
# click the button to bring up alert
webElem$clickElement()

# Check the Alert text
> remDr$getAlertText()
[[1]]
[1] "Press a button!"
# Accept the alert. Equivalent to pressing the OK button.
remDr$acceptAlert()

你能分享你用来访问它的网页URL和代码吗?我脑子里没有一个特定的页面:我正在学习如何使用Selenium,并且正在使用RSelenium intro Vignette这里有一个带有对话框的页面示例:在不引发异常的情况下,检查元素是否存在的最佳方法是什么?如果你能想象你访问的网页可能有或没有对话框,可能有或可能没有框架,可能有或可能没有等等。拥有10个tryCatch子句并不可怕。我的问题,很清楚,是如何检查某些东西是否存在,而不是如何与元素交互是的,我理解你的问题。我认为这是一个公平的观点,谢谢你提出这个问题。当前,当selenium服务器抛出异常时,我会引发一个错误。我可以选择将此错误更改为警告,如果有帮助,可以打开或关闭警告。如果是这样的话,也许可以在上提交一个问题,我将添加这样一个机制。我认为如果有一个函数只检查一个元素是否存在,而不返回该元素,这会很有帮助。显然,我可以自己轻松编写一个来尝试匹配异常,但如果它是包的一部分,那就更好了。不管怎样,只是我的thought@Alex硒在很大程度上被设计为硒的包装物。Selenium被明确设计为在找不到元素并且没有
isElementPresent
方法时抛出错误。有趣的是,它曾经有过这样一种方法。
> try(remDr$findElement("id", "I DONT EXIST"), TRUE)
> remDr$status
[1] 7
> remDr$statusCodes[which(remDr$statusCodes$Code == remDr$status),]
  Code       Summary                                                                         Detail
3    7 NoSuchElement An element could not be located on the page using the given search parameters.