I've found that the fire_event can be very problematic which
extensions/alerts is using.  watir-webdriver will be updated to use
selenium-webdriver's switch_to in the near future.  But in the mean time you
can take a look at handling this buy  adding an alert box helper to Watir:

https://github.com/ccyphers/whirlwind/blob/master/lib/watir.rb

Then you can do stuff like:
@browser.alert_box.text
@browser.alert_box.dismiss


On Tue, Oct 25, 2011 at 11:41 AM, Dan <dfra...@gmail.com> wrote:

> Hello,
>
> I've tried to implement the dialog handling as described here on
> http://watirwebdriver.com/javascript-dialogs/ using the example at
> http://www.w3schools.com/js/js_popup.asp, but it doesn't seem to work.  I
> believe the application I'm working on is using the same approach that this
> example is to the alerts, but for some reason I can't get it to dismiss this
> pop-up.  I'm successful in disabling it altogether
> using browser.execute_script("window.alert = function() {}"), but I'd really
> prefer to be able to capture what the actual alert was and to dismiss it
> like a user would, which seems like "watir-webdriver/extensions/alerts"
> would allow me to do.
>
> Here's what I tried:
>
> require 'rubygems'
> require 'watir-webdriver'
> require "watir-webdriver/extensions/alerts"
>
> browser = Watir::Browser.new :firefox
> browser.goto "http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert";
> browser.frame(:class => "result_output").button(:value => "Show alert
> box").wait_until_present
> browser.frame(:class => "result_output").button(:value => "Show alert
> box").click
>
> browser.alert do
>   browser.button(:value => 'OK').click
> end #=> 'the alert message'
>
> This is the exception I get :
>
> C:/ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.3.3/lib/watir-webdriver/elements/element.rb:248:in
> `assert_exists': unable to locate element, using {:value=>"OK",
> :tag_name=>"button"} (Watir::Exception::UnknownObjectException)
>
> Thanks!
>
> --
> Before posting, please read http://watir.com/support. In short: search
> before you ask, be nice.
>
> watir-general@googlegroups.com
> http://groups.google.com/group/watir-general
> watir-general+unsubscr...@googlegroups.com
>

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to