处理“您确定要离开此页面吗” Selenium 2.0 中的消息
使用硒2.0 提交网络表单后,弹出消息会出现“您确定要离开此页面吗”消息,如何让 selenium 按“确定”或禁用此弹出窗口?
我已经尝试过
Alert alert = driver.switchTo().alert();
alert.accept();
或
alert.dismiss();
编辑:
快速修复,我只是使用 JS 覆盖了弹出功能,
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.onbeforeunload = function() {};");
form.submit();
这将停止将禁用此弹出窗口,对于 js 警报、确认和提示框也可以这样做
Using Selenium 2.0
After Submitting a web form, A popup msg comes up with the "are you sure you want to navigate away from this page" message, How do I get selenium to press OK or disable this popup?
I have already tried
Alert alert = driver.switchTo().alert();
alert.accept();
or
alert.dismiss();
edit:
quick fix, I just overwrote the popup function using JS
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.onbeforeunload = function() {};");
form.submit();
this will stop will disable this popup, the same can be done for js alerts, comfirm and prompt boxes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个答案是否有帮助:
http://code.google.com/p/selenium/issues /detail?id=27#c6
总体而言,该线程提出了与您类似的问题。您正在尝试将其作为警报处理,看看是否可以将其作为 js 确认对话框处理。
See if this answer helps:
http://code.google.com/p/selenium/issues/detail?id=27#c6
Overall, the thread raises a similar concern as yours. You are trying to handle this as an alert, see if you can handle this as a js confirmation dialog.