gpt4 book ai didi

python - Selenium 可以很好地检测弹出对话框,但无法处理它

转载 作者:行者123 更新时间:2023-12-01 08:59:56 25 4
gpt4 key购买 nike

我的配置如下:

  • Selenium :3.14.1
  • IEDriverServer:3.9 -- x64
  • IDE:IE 11
  • Python 3.4.4

我只是想接受打开的弹出警报。我已经实现了以下代码:

try:

WebDriverWait(driver, 10).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert.accept()
print("Accept")

except TimeoutException:

print("no alert")

程序检测到弹出对话框,打印“接受”消息,但不干扰它。我也不异常(exception)(消息“无警报”)或错误程序,弹出警报保持打开状态。命令 .dismiss() 也不起作用。

我尝试了几种不同的 IE 11 驱动程序,但没有成功。

如果有人可以帮助我,我将不胜感激:-)。

最佳答案

您似乎有缩进错误。

所以,你的代码应该是:

try:

WebDriverWait(driver, 10).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert.accept()
print("Accept.")

except TimeoutException:

print("No alert.")

希望对你有帮助!

关于python - Selenium 可以很好地检测弹出对话框,但无法处理它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52535477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com