Reputation: 133
I just read that new Watir version (3.1.0) has "support for Alert API". What can I actually do with this API?
Is it meant for dealing with javascript popup windows? If so, what command can I use to click "OK" in popup window? Or how can I read title & text of popup window?
I tried "browser.alert.ok
" after updating Watir to 3.1.0 but just got some error message...
(There is not yet any clear documentation about this, and trying to interpret the source code is not my strongest side...)
Upvotes: 3
Views: 615
Reputation: 57312
Alert API is for dealing with JavaScript popups.
browser.alert.ok
should work. Could you provide the error message?
I am not sure about getting popup title, but you can get it's text with browser.alert.text
More information: http://watir.github.io/docs/javascript-dialogs/
Upvotes: 2
Reputation: 133
browser.alert.ok should work. Could you provide the error message?
Sure. First, here is Watir code that I used:
require 'watir'
b = Watir::Browser.start "www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
b.maximize
b.frame(:name, "view").button(:text, "Show alert box").click_no_wait
sleep 2
b.alert.ok
And here is the error message:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi n_32/functions.rb:319: [BUG] Segmentation fault ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
-- control frame ---------- c:0012 p:---- s:0052 b:0052 l:000051 d:000051 CFUNC :enum_child_windows c:0011 p:0065 s:0046 b:0046 l:002478 d:002478 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:319 c:0010 p:0015 s:0038 b:0038 l:0018e4 d:0018e4 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:200 c:0009 p:0025 s:0033 b:0033 l:000032 d:000032 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/functions.rb:147 c:0008 p:0035 s:0025 b:0024 l:000023 d:000023 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/win_32/window.rb:247 c:0007 p:0017 s:0020 b:0020 l:000019 d:000019 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/rautomation-0.7.2/lib/rautomation/window.rb:220 c:0006 p:---- s:0015 b:0015 l:000014 d:000014 FINISH c:0005 p:0079 s:0013 b:0013 l:000012 d:000012 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialogs/alert.rb:38 c:0004 p:0011 s:0010 b:0010 l:000009 d:000009 METHOD C:/Ruby192/lib/ruby/gems/1. 9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialogs/alert.rb:27 c:0003 p:0107 s:0007 b:0007 l:00043c d:0018c0 EVAL C:/watir_testit/pop.rb:6 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
-- Ruby level backtrace information ----------------------------------------
C:/watir_testit/pop.rb:6:in <main>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialog
s/alert.rb:27:in
ok'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-classic-3.1.0/lib/watir-classic/dialog
s/alert.rb:38:in dialog'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/window.rb:
220:in
method_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/window.rb:247:in child'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:147:in
child_window_locators'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:200:in control_hwnd'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:319:in
find_hwnd'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rautomation-0.7.2/lib/rautomation/adapter/wi
n_32/functions.rb:319:in `enum_child_windows'
[NOTE] You may have encountered a bug in the Ruby interpreter or extension libraries. Bug reports are welcome. For details: http://www.ruby-lang.org/bugreport.html
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
Upvotes: 0