driver.switch_to.alert().accept() TypeError: ‘Alert‘ object is not callable

“D:\Program Files (x86)\Python38\python.exe” C:/Users/Administrator/PycharmProjects/pythonProject/selenium/01-selenium演示代码.py
Traceback (most recent call last):
File “C:/Users/Administrator/PycharmProjects/pythonProject/selenium/01-selenium演示代码.py”, line 25, in
driver.switch_to.alert().accept()
TypeError: ‘Alert’ object is not callable

Process finished with exit code 1

原因分析
‘Alert’ object is not callable 的含义为Alert不能被函数调用,它不是一个函数。

解决方案
将alert后的括号去掉。

正确代码:

browser.switch_to.alert.accept()

猜你喜欢

转载自blog.csdn.net/xiaoxiamimm/article/details/112223706