处理“您确定要离开此页面"硒2.0中的消息 [英] handling "are you sure you want to navigate away from this page" Msg in Selenium 2.0

查看:119
本文介绍了处理“您确定要离开此页面"硒2.0中的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用硒2.0 提交Web表单后,弹出消息msg出现您确定要离开此页面"消息,如何获取硒以按OK或禁用此弹出窗口?

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?

我已经尝试过

    Alert alert = driver.switchTo().alert();
    alert.accept(); 

    alert.dismiss();

快速修复,我只是使用JS覆盖了弹出功能

quick fix, I just overwrote the popup function using JS

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.onbeforeunload = function() {};"); 

    form.submit();

此操作将停止,将禁用此弹出窗口,对js警报,确认和提示框也可以这样做

this will stop will disable this popup, the same can be done for js alerts, comfirm and prompt boxes

推荐答案

查看此答案是否有帮助:
http://code.google.com/p/selenium/issues/detail?id = 27#c6

See if this answer helps:
http://code.google.com/p/selenium/issues/detail?id=27#c6

总的来说,该线程引起了与您类似的担忧.您正在尝试将其作为警报来处理,看看是否可以将其作为js确认对话框来处理.

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.

这篇关于处理“您确定要离开此页面"硒2.0中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆