我有以下弹出警报,我想在文件上传后处理。我使用了下面的代码,它抛出了下面的错误。
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 alert在 Python
+ 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/