ruby - WebDriver 在测试后关闭 Internet Explorer

标签 ruby internet-explorer webdriver

我在 Ruby 中运行 WebDriver 测试,但在关闭 Internet Explorer 浏览器时遇到问题:当我想关闭时浏览器窗口,IE弹出提示“是否确定要离开此页面”,并有“离开此页面”和“留在此页面”两个选项。

我尝试了几种关闭浏览器的方法,但都没有成功:

driver.quit
driver.close

此外,WebDriver 无法将此弹出窗口识别为 JavaScript 弹出窗口,因此

driver.alert.ok 
driver.switch_to.alert

方法也不适用。 我使用的是 IE9IEDriverServerx86 v. 2.24.2

我很感激你能提供的任何帮助

最佳答案

你需要先抑制onbeforeunload事件:

driver.execute_script "window.onbeforeunload = function(e){};"
driver.quit

关于ruby - WebDriver 在测试后关闭 Internet Explorer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11500155/

相关文章:

css - 在 IE/Chrome/Firefox 中打印预览(或打印)时不显示图像

Java、Selenium 中链接捕获器上的 java.lang.NullPointerException

ruby - 每个 Ruby 中的自动计数器?

ruby-on-rails - Rails3 : HOWTO Override/Reopen a class within a Gem and the Rails initialization process

javascript - Internet Explorer 10 和 11 在输入聚焦时删除占位符文本

javascript - Internet Explorer jquery :contains issue

java.lang.OutOfMemory错误: GC overhead limit exceeded"while reading excel file using apache POI

javascript - 如何检测 HTML 代码中的文本

mysql - 更改多个数据库的连接名称

ruby - 在 Windows 8 上安装 mysql2 gem