如何从浏览器中删除通知和警报?硒蟒蛇 2.7.7 [英] how can i remove notifications and alerts from browser? selenium python 2.7.7

查看:17
本文介绍了如何从浏览器中删除通知和警报?硒蟒蛇 2.7.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网页中提交信息,但 selenium 抛出此错误:

I am trying to submit information in a webpage, but selenium throws this error:

UnexpectedAlertPresentException:警报文本:此页面正在询问您确认您要离开 - 您输入的数据可能不是保存.,>

UnexpectedAlertPresentException: Alert Text: This page is asking you to confirm that you want to leave - data you have entered may not be saved. , >

这不是请假通知;这是通知的图片 -

It's not a leave notification; here is a pic of the notification -

.

如果我点击不再显示此通知,则不会保存我的操作;有没有办法保存或禁用所有通知?

If I click in never show this notification again, my action doesn't get saved; is there a way to save it or disable all notifications?

我使用的是火狐.

推荐答案

您可以使用 chrome 选项禁用浏览器通知.示例代码如下:

You can disable the browser notifications, using chrome options. Sample code below:

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

这篇关于如何从浏览器中删除通知和警报?硒蟒蛇 2.7.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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