Selenium + Perl:检查警报是否存在?

编程入门 行业动态 更新时间:2024-10-28 04:18:15
本文介绍了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:检查警报是否存在?

本文发布于:2023-11-27 15:42:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   是否存在   Selenium   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!