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?

在提交web表单后使用Selenium 2.0,弹出的msg会出现“您确定要离开这个页面吗”的消息,我如何让Selenium按OK或禁用这个弹出窗口?

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

快速修复,我只是用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

这将停止将禁用此弹出,同样可以对js警报、comfirm和提示框执行此操作

1 个解决方案

#1


3

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

看看这个答案是否有用: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.

总的来说,这条线引发了与你类似的担忧。您试图将其作为警报处理,看看是否可以将其作为js确认对话框处理。

更多相关文章

  1. web基础之自动处理表单填装javabean
  2. ***100分,谁有用java mail做的把表单直接发送到邮箱的网页例子,发

随机推荐

  1. JavaScript 实现GridView汇总
  2. 如何使用try,catch在错误处理中打印消息
  3. javascript之DOM技术(二)
  4. 有没有办法在javascript控制台中将上下文
  5. 如何使用Require JS配置具有第三方js依赖
  6. JavaScript——数组(三)数组方法汇总
  7. 切换元素类并使用旧类在视图中添加新元素
  8. 阻止用户在表单字段中输入
  9. req.files.upload.length返回文件计数为
  10. js 学习之路9:运算符