Python / Selenium-确认弹出窗口接受

时间:2019-03-14 15:32:42

标签: python-3.x selenium

弹出的确认框上有什么想法吗?当我完成此工作时,我知道代码正在切换到警报框-但引用错误似乎好像我需要一种其他方法-除了“接受”。任何想法将不胜感激。

环境:Python 37.32 / Selenium 2.33

dscopy = browser.find_element_by_name('_eventId_discontinueAndCopy')
dscopy.click()

time.sleep(3)
alert = browser.switch_to_alert
alert.accept()

(引用) erap.py”,第57行,在     alert.accept() AttributeError:“函数”对象没有属性“接受”

1 个答案:

答案 0 :(得分:2)

您需要调用switch_to_alert

dscopy = browser.find_element_by_name('_eventId_discontinueAndCopy')
dscopy.click()

time.sleep(3)
alert = browser.switch_to_alert()
alert.accept()

编辑:

@Corey Goldberg评论:

不推荐使用Switch_to_alert,因此您应该使用:

alert = browser.switch_to.alert
alert.accept()

希望这对您有帮助!

相关问题