关于 selenium 弹出框点击确认的问题
用 selenium 进行弹出框确认操作
def accept_alert(self):
try:
alert=self.driver.switch_to.alert()
self.sleep(1)
alert.accept()
except NoAlertPresentException as e:
点击按钮后跳出弹出框,点击确定后页面会自动关闭
def receive_all_docs(self):
self.click(*self.chkall_checkbox)
self.click(*self.response_btn)//此按钮会触发弹出框
self.accept_alert()
运行后,他会闪出弹出框, 就一闪而过,然后提示以下错误:
Traceback (most recent call last):
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 21, in <module>
manage()
File "e:\Dropbox\17.Develop\5.Project\autozboa\run.py", line 12, in manage
m.receive_docs() # 接收文件
File "e:\Dropbox\17.Develop\5.Project\autozboa\manage.py", line 57, in receive_docs
sw.receive_all_docs()
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\pages\sw_page.py", line 27, in receive_all_docs
self.click(*self.response_btn)
File "e:\Dropbox\17.Develop\5.Project\autozboa\zboa\framework\base_page.py", line 100, in click
log.info('元素 \' %s \' 已被点击.' % el.text)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webelement.py", line 76, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "E:\Dropbox\17.Develop\5.Project\autozboa\env\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 241, in check_response
raise exception_class(message, screen, stacktrace, alert_text)
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: 确认对选中的文档执行接收操作?
Message: Modal dialog present with text: 确认对选中的文档执行接收操作?
请问是什么原因?怎么让他顺利执行
推荐文章: