我正在使用 selenium webdriver 使用 python 和生菜运行基本的 CRUD 测试。
我的所有其他测试都运行良好,但是当我单击“删除”时,会出现一个模式对话框,要求用户确认他们想要删除该用户。弹出窗口出现的那一刻,我得到了下面的异常。我已经浪费了 2 个小时试图让它发挥作用。我想有一个简单的修复方法。
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
UnexpectedAlertPresentException: Message: u'Modal dialog present' ; Stacktrace:
at nsCommandProcessor.prototype.execute (file:///tmp/tmpeV2K89/extensions/fx[email protected] /cdn-cgi/l/email-protection/components/command_processor.js:11520:13)
Steps.py 中引发错误的行是这样的。
world.browser.find_element_by_link_text("Delete User").click()
该元素的 html 是这样的。
<a href="/users/5910974510923776/delete" onclick="return confirm('Are you sure you want to delete this user?');">Delete User</a>
你需要切换到警报 https://www.selenium.dev/documentation/en/webdriver/js_alerts_prompts_and_confirmations/#confirm并接受它:
world.browser.find_element_by_link_text("Delete User").click()
alert = world.browser.switch_to.alert
alert.accept()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)