Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
如何在ruby webdriver中使用等待警报_Ruby_Selenium_Webdriver - Fatal编程技术网

如何在ruby webdriver中使用等待警报

如何在ruby webdriver中使用等待警报,ruby,selenium,webdriver,Ruby,Selenium,Webdriver,因此,我想等待直到显示警报,然后使用通常的开关发出警报并获取文本 已经提供了Java的解决方案 目前我使用睡眠,但每个人都知道这有多糟糕 这就是我所拥有的- sleep 3 a = $driver.switch_to.alert begin a.text == 'Your alert here.' rescue verify { assert_match "true","false","The alert failed to be displayed"} end a.accept 我

因此,我想
等待
直到显示警报,然后使用通常的
开关
发出警报并
获取文本

已经提供了Java的解决方案

目前我使用
睡眠
,但每个人都知道这有多糟糕

这就是我所拥有的-

sleep 3
a = $driver.switch_to.alert
begin
  a.text == 'Your alert here.'
rescue
  verify { assert_match "true","false","The alert failed to be displayed"}
end
a.accept
我在找像这样的东西

$wait.until { a = $driver.switch_to.alert }
begin
  a.text == 'Your alert here.'
rescue
  verify { assert_match "true","false","The alert failed to be displayed"}
end
a.accept
但这不起作用,它基本上忽略了等待(顺便说一句,我有30秒的等待)。
正如我所提到的,我需要知道如何在RUBY-TestUnit中执行此操作,如果您使用watir和watir webdriver,您可以执行类似$browser的操作。wait_uniti_present

没有方法等待警报出现。但您可以使用以下代码等待警报出现。一旦出现警报,它将退出循环

status=true
while (status)
alert = driver.switch_to.alert rescue "exception happened"
if (alert == "exception happened")
status = true
alert = "nothing happened"
else
status = false
end
end

谢谢你的回复。我想这会起作用,但会导致另一个问题,时间问题。如果警报从未出现,我不希望出现无限循环。我想等30秒,如果警报没有出现。我想考试不及格。