Selenium + Perl:检查警报是否存在? [英] Selenium + Perl: Check if alert exists?

查看:91
本文介绍了Selenium + Perl:检查警报是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium 2. *在Linux上运行,并且使用Firefox作为浏览器。

Selenium 2.* is running on Linux with Firefox as the browser.

我将Perl与Selenium :: Remote :: Driver模块结合使用,服务器。

I am using perl with the Selenium::Remote::Driver module to interact with the server.

是否可以检查警报是否存在? perl模块提供了几个功能,可以在警报上单击确定或从中获取文本,但是如果没有警报,这将引发错误-如何避免错误并仍然摆脱任何警报?

Is there anything available to check if an alert is present? The perl module provides several functions to click OK on an alert, or to get the text from it, but this will raise an error if there is no alert - how to avoid an error and still get rid of any alert?

基本上,我想在页面完成加载后删除所有警报(如果有的话),但不确定如何?

Basically, I want to remove all alerts when a page finished loading (if any), but not sure how?

另一个我尝试过的选项是通过在firefox配置文件中设置一个变量来禁用所有警报(当您自己使用浏览器时,该变量将起作用),但是以某种方式,当Selenium使用浏览器时,警报仍然存在,因为我认为Selenium会自行处理警报,因为始终设置为true的 handlesAlerts功能,但我不确定如何禁用它。如果无法检查是否存在警报,则可能是解决方案。

Another option that I tried is disabling all alerts by setting a variable in the firefox profile (which works when you use the browser yourself), but somehow the alert is still there when the browser is used by Selenium because i think Selenium handles the alert itself because of the "handlesAlerts" capability, which is always set to true, and I'm not sure how to disable it. It may be the solution if it's not possible to check for the existence of an alert.

有人知道吗?

推荐答案

您可以尝试关闭警报,使用eval块处理异常

You could try to dismiss alerts, use eval block to handle exceptions

eval {
   $driver->accept_alert;
};
if ($@){
 warn "Maybe no alert?":
 warn $@;
}

这篇关于Selenium + Perl:检查警报是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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