使用的Python 3和硒>Chromedriver。Python和硒 - 禁用所有警报
我正在运行一个python脚本来从不同的网站刮东西。
我需要打开和关闭很多不同的网站。
问题:
我的程序崩溃时,警报被触发。
selenium.common.exceptions.UnexpectedAlertPresentException:警报文本:无 消息:意外警告开放
我是什么试图解决的情况呢?
当我做driver.get(),我立即运行:
driver.execute_script("window.alert = null;")
driver.execute_script("Window.prototype.alert = null;")
权做driver.close()之前,我跑:
driver.execute_script("window.onbeforeunload = null;")
右后做事driver.close(),我这样做:
from selenium.common.exceptions import NoAlertPresentException
...
driver.close()
# any alert asking me if I really want to close?
try:
driver.switch_to.alert.accept()
except NoAlertPresentException:
pass
我在做什么?
没什么,程序总是崩溃:
问题:
请问有什么可以设置整个事情,要禁用每个警报。
如果不可能,我该如何接受他们,或者至少这样做才能使程序保持流畅?
[关闭弹出窗口并警告窗口硒网络驱动器Firefox的配置文件]的可能重复提到的网站被采取stackoverflow.com/questions/20974729/selenium-web-driver-firefox-profile-disable-popup-and-alert-windows) –
当我访问该网站时,我没有看到弹出窗口。你能翻译什么弹出所有关于?谢谢 – DebanjanB
@DebanjanB这是典型的“你确定要离开这个页面吗?”弹出。它恰好有时只出现。 –