Waitr Webdriver 中的警报框

发布于 2024-09-18 07:21:06 字数 246 浏览 3 评论 0原文

我在这里看了一下: http://wiki.openqa.org/display/ WTR/JavaScript+Pop+Ups

每个解决方案都适用于 Windows 上的 IE。我在 Mac 上使用 Firefox。有没有办法单击 JavaScript 警报框的“确定”?

I had a look here: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups

Every solution is for IE on Windows. I am using Firefox on Mac. Is there a way to click on OK of a JavaScript alert box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2024-09-25 07:21:06

正确处理提醒和提示的问题仍在研究中 WebDriver,但一个常见的解决方法是使用execute_script()覆盖窗口函数,即

browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }")
browser.button(:id => "trigger-alert").click
browser.execute_script("return window.lastAlert") #=> "the message"

因为我想避免一堆猴子补丁四处浮动(Watir社区中的一个常见问题),所以我添加了一些辅助方法作为可选要求 - 在下一个版本之后,您应该能够执行以下

require "watir-webdriver/extensions/alerts"

browser.alert do
  browser.button(:id => "alert").click 
end #=> "the alert message"

browser.confirm(true) do
  browser.button(:id => "confirm").click
end #=> "the confirm message"  

browser.prompt("returned value") do
  browser.button(:id => "prompt").click 
end #=> { :message => "foo", :default => "bar" }

操作 :这是暂时的,当 WebDriver 中的问题得到解决后,该 API 可能会在将来被删除。

更新:

现已实施正确的警报处理。上面的例子现在可以这样完成:

browser.button(:id => "alert").click
browser.alert.ok

browser.button(:id => "confirm").click
browser.alert.ok # or browser.alert.close

browser.button(:id => "prompt").click
alert = browser.alert
alert.text #=> "foo"
alert.ok

Proper handling of alerts and prompts is still being worked on in WebDriver, but a common workaround is to overwrite the window functions using execute_script(), i.e.

browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }")
browser.button(:id => "trigger-alert").click
browser.execute_script("return window.lastAlert") #=> "the message"

Since I'd like to avoid a bunch of monkey patches floating around (a common problem in the Watir community), I've added some helper methods as an optional require - after the next release you should be able to do:

require "watir-webdriver/extensions/alerts"

browser.alert do
  browser.button(:id => "alert").click 
end #=> "the alert message"

browser.confirm(true) do
  browser.button(:id => "confirm").click
end #=> "the confirm message"  

browser.prompt("returned value") do
  browser.button(:id => "prompt").click 
end #=> { :message => "foo", :default => "bar" }

Note that this is temporary and the API may be removed in the future when the issue is resolved in WebDriver.

UPDATE:

Proper alert handling is now implemented. The above example would now be done like this:

browser.button(:id => "alert").click
browser.alert.ok

browser.button(:id => "confirm").click
browser.alert.ok # or browser.alert.close

browser.button(:id => "prompt").click
alert = browser.alert
alert.text #=> "foo"
alert.ok
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文