Selenium Web-Driver Firefox配置文件 - 禁用弹出窗口和警报窗口 [英] Selenium Web-Driver Firefox Profile - Disable popup and alert windows

查看:330
本文介绍了Selenium Web-Driver Firefox配置文件 - 禁用弹出窗口和警报窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到某些网站的问题,导致我的浏览器在尝试切换到其他网址时提示警报,甚至关闭浏览器。一些例子:

I am having a problem with certain websites that cause my browser to prompt an alert when I try to switch to a different URL, or even close the browser. Some examples:

http://www.dollardays.com/

为了使用Selenium解决警报问题,我需要切换到该警报,然后有时接受它并有时拒绝它(取决于警报的内容)。

In order to workaround the alert with Selenium, I need to switch to that alert, and then sometimes accept it and sometimes reject it (depending on the contents of the alert).

我希望避免解决这个问题因为:

I wish to avoid solving this problem that way because:


  1. 我需要猜测是否应接受警报或拒绝警报。

  1. I need to guess whether I should accept the alert or reject the alert.

切换到警报有时会引发异常,即使警报仍然存在。

Switching to the alert sometimes throws an exception, even though the alert is present.

我需要在Firefox配置文件中设置哪些首选项,以防止浏览器发出此类警报(或任何其他警报)?

What preferences do I need to set in the Firefox-Profile, in order to prevent the browser from issuing such alerts (or any other alerts for that matter)?

Java或Python中的答案将受到高度赞赏。

Answers in Java or Python will be highly appreciated.

谢谢

推荐答案

据我所知,您只能全局禁用该行为。
有一个名为 dom.disable_beforeunload 的偏好设置。您应该将其值更改为true。使用Selenium,您可以创建新的自定义Firefox配置文件:

To my knowledge you can only disable that behaviour globally. There is a preference called dom.disable_beforeunload. You should change its value to true. With Selenium, you can create a new customized Firefox profile:

FirefoxProfile customProfile = new FirefoxProfile();
customProfile.setPreference("dom.disable_beforeunload", true);
FirefoxDriver driver = new FirefoxDriver(customProfile);

这篇关于Selenium Web-Driver Firefox配置文件 - 禁用弹出窗口和警报窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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