python selenium禁用os弹出窗口 [英] python selenium disable os pop-ups
问题描述
我正在尝试使用Python
中的selenium
自动执行文件下载过程.到现在为止,我已经成功编写了实现该代码的代码.但是,有一个非常令人不安的小问题:每次我在Firefox
中启动程序(我使用webdriver.Firefox()
)时,总会出现一个操作系统弹出窗口,询问我allow the website to use 'Microsoft Office'
并阻止整个程序.由于这是一个操作系统问题,因此我无法使用selenium
与它进行交互...我也尝试了driver.switch_to_alert()
方法,但是它不起作用.
I am trying to automate the file downloading process with selenium
in Python
. Until now I succeeded in writing the code to realize it. But there is just a little problem which is pretty disturbing: Each time I launch the program in Firefox
(I use webdriver.Firefox()
), there is always an OS pop-up which asks me allow the website to use 'Microsoft Office'
and blocks the whole program. Since it is an OS problem, I cannot interact with it using selenium
...I also tried driver.switch_to_alert()
method but it didn't work.
您知道如何解决吗?
非常感谢!!
推荐答案
try:
WebDriverWait(driver, 40).until(EC.alert_is_present(),
'Timed out waiting for PA creation ' +
'confirmation popup to appear.')
alert = driver.switch_to.alert()
alert.accept()
这篇关于python selenium禁用os弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!