There are two options to handle alerts with watir-webdriver:

# use the alert helper to override the alert function:

  require "watir-webdriver/extensions/alerts"

  browser.alert do
    browser.button.click # action that triggers the alert
  end

# reach into the WebDriver alert API

  browser.button.click # action that triggers the alert
  browser.driver.switch_to.alert.dismiss

The first API was made before WebDriver had any alert support, and is
subject to be removed in the future. I'd recommend you stick to the latter
for now.





On Sat, Oct 1, 2011 at 7:26 PM, Jeff Nyman <jeffny...@gmail.com> wrote:

> Hey all.
>
> I've tried searching for this on my own but looking for specific
> solutions in Watir or Watir-WebDriver is often a needle in a haystack
> venture. In this case, I have an application that has a JavaScript
> alert that pops up when an OK button is clicked. I need to get the
> message in the alert box and then click OK to get rid of it.
>
> I can do this easily in Selenium (most notably using the alertAssert)
> but I'm having trouble seeing how to do it in Watir.
>
> I saw this page: http://wiki.openqa.org/display/WTR/JavaScript+Pop+Ups.
> It mentions this line:
>
> $ie.javascript_dialog.button('OK').click
>
> That does nothing for me but I'm using watir-webdriver as opposed to
> just watir so that might be why that is.
>
> Some of the blog posts (like
> http://watir.com/2011/01/14/testing-webpages-with-javascript-popups-correctly/
> )
> I've found indicate more how you can just ignore the JavaScript alert
> -- but that's not a good way to do things if your application requires
> the alert to be present and show text. I have to test for that. I
> would be okay with dismissing the alert if there was some equivalent
> of Selenium's assertAlert so that I could at least get the message
> returned.
>
> Any thoughts? Not being able to handle JavaScript dialogs -- annoying
> as they are -- is definitely a deal breaker so I'm open to any
> suggestions.
>
> - Jeff
>
>
> --
> 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