使用的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這是典型的「你確定要離開這個頁面嗎?」彈出。它恰好有時只出現。 –