首页 > 其他 > 详细

selenium——关于alert弹框踩过的坑:TypeError: 'Alert' object is not callable

时间:2020-05-14 17:16:44      阅读:108      评论:0      收藏:0      [点我收藏+]

 

报错1:__init__() takes 1 positional argument but 2 were given

技术分享图片

 

 

 原因:进入源码可以看到,alert_is_present是一个class类,因此调用的时候要加上括号alert_is_present()

技术分享图片

 

 

 

报错2:TypeError: ‘Alert‘ object is not callable

解决方法:

技术分享图片

 

正确写法:

    def accept_alert(self):
        """确认弹框"""
        try:
            WebDriverWait(self.driver, self.max_wait_time).until(EC.alert_is_present())
            alert = self.driver.switch_to.alert
            alert.accept()
        except Exception as e:
            raise e

 

selenium——关于alert弹框踩过的坑:TypeError: 'Alert' object is not callable

原文:https://www.cnblogs.com/erchun/p/12889923.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!