javascript - 在 Selenium Python 中处理警报

标签 javascript python selenium

我有以下弹出警报,我想在文件上传后处理。我使用了下面的代码,它抛出了下面的错误。

enter image description here

wait.until(EC.alert_is_present())
driver.switch_to.alert().accept()

Traceback (most recent call last): File "update.py", line 45, in driver.switch_to.alert().accept() TypeError: 'Alert' object is not callable

为什么会这样?我以这种方式处理过类似的警报(那个警报有一个取消按钮?)。

最佳答案

two ways to accept alertPython + selenium 中可用(还有用于 execute_script()JavaScript 代码,但它与当前版本无关问题):

driver.switch_to_alert().accept() # deprecated, but still works
driver.switch_to.alert.accept()

请注意,在第二行中,您不需要像在代码中那样调用 alert()

关于javascript - 在 Selenium Python 中处理警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42005956/

相关文章:

python - 如何访问 Spark PipelineModel 参数

selenium - 当我将 $cdc_lasutopfhvcZLmcfl 替换为任何尝试避免通过 chromedriver.exe 被某些站点检测到的内容时它不起作用

javascript - 如何将 UTC 字符串转换为访问者本地时区的 momentJS?

javascript - 如何在我的 javascript 生成列表的 <li> 部分中放置更多超链接

python - 使用 pandasql 时在 VS Code 中使用多个制表符间距设置和注释

python - 使用机器人框架在谷歌翻译中点击 Selenium 按钮

python - 如何在 Selenium 中的 xpath 表达式中使用单引号?

javascript - 为什么带有amqplib Consumer函数的nodejs是闭包?

javascript - 未捕获的类型错误 : Cannot set property propTypes of function Settings(props)

python - 聚合和重命名字典中的键