2

单击按钮后,将打开一个新的 Windows 警报。我尝试使用此代码:

 browser.button(:name => 'OpProvisionalCreate').click     

 browser.execute_script("window.confirm = function() {return true}")  

 browser.window(:title => "Message from webpage").use do
   browser.button(:id => "close").click
 end

但我收到一条错误消息:

:in `<top (required)>': undefined method `window' for #<Watir::IE:0x1a76990> (NoMethodError)
4

1 回答 1

3

您可能正在使用旧版本的 watir-classic。Browser#window方法是在 watir-classic 3.0.0 中添加的。但是关闭 JavaScript 弹出窗口应该在 Alert API 的帮助下完成:

# this will open the popup? Use #click_no_wait in that case.
browser.button(:name => 'OpProvisionalCreate').click_no_wait
# close the popup
browser.alert.close

从Container and Alert 文档中了解更多信息。如果要使用上面提到的 Alert API,则需要使用 watir-classic 3.1.0 或更新版本。

于 2013-02-10T15:11:22.163 回答