Re: Waitir: Ignoring modal wait dialogs during ajax call

129 views
Skip to first unread message

Ankita@Adslot

unread,
May 9, 2013, 9:29:00 PM5/9/13
to watir-...@googlegroups.com
what if you add 
browser.text_field(:id, "subscriber_id").wait_until_present(timeout = 100)
before 
browser.text_field(:id, "subscriber_id").set("11111")
On Saturday, April 20, 2013 7:56:08 PM UTC+10, Christian Scheid wrote:

Hi,

I'm just starting to use Waitir and have the following issue: The Waitir script is supposed to execute a search on a KendoUI Grid element which in turn displays a modal spinner when performing an ajax call to retrieve the search results. (script below). Waitir throws an UnhandledAlertError because a modal dialog is present (below). I've seen Waitir code to handle javascript pop ups but I haven't found a solution how to handle a modal pop-up without any buttons like a spinner.

Any ideas?

Thanks!

Error: nsCommandProcessor.prototype.execute': Modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError)

Script:

require 'watir'
require 'watir-webdriver'

browser = Watir::Browser.start "http://localhost:8080/admin/index.php/login"
browser.link(:text, "Manage Members").wait_until_present
browser.link(:text, "Manage Members").click
browser.text_field(:id, "subscriber_id").set("11111")
browser.button(:value,"Search").click

Dan

unread,
May 9, 2013, 9:54:19 PM5/9/13
to watir-...@googlegroups.com
There's a few funny things about your script.  You really only need to require watir or watir-webdriver.  If you're using the watir gem it'll either load the watir-classic gem, if you ask it for ie, or watir-webdriver gem if you ask it for chrome or firefox.

Secondly, your syntax for starting a browser is incorrect.  It should be .new not .start.
browser = Watir::Browser.new :chrome

As far as handling the alert, you can do something like this after you click on whatever element that causes the spinner to popup.  This below will just wait until the dialog goes away.

browser.alert.wait_while_present

It's nice to see that you're using the wait methods.  It seems lots of people who are just starting out end up using sleeps which is bad practice.  You can actually collapse two lines into one like below as well.

browser.link(:text, "Manage Members").when_present.click

Andrew Leaf

unread,
May 10, 2013, 11:58:31 AM5/10/13
to watir-...@googlegroups.com


On Thursday, May 9, 2013 8:54:19 PM UTC-5, Dan wrote:
Secondly, your syntax for starting a browser is incorrect.  It should be .new not .start.
browser = Watir::Browser.new :chrome

Hello Dan,

I just wanted to clarify that is valid Watir code.

browser = Watir::Browser.start "http://localhost:8080/admin/index.php/login"
This is valid Watir code.  Calling Watir::Browser.start with a URL as an argument is the same as:
browser = Watir::Browser.new
browser.goto "browser "http://localhost:8080/admin/index.php/login"
You may need to dismiss the modal by clicking on whichever element dismisses the modal for the user.  Without page HTML when the modal is visible and an indication of which line is giving the failure in your Watir code, it's difficult to provide any further guidance.
If you have HTML available, paste it in so we can further troubleshoot.
Andrew

Dan

unread,
May 10, 2013, 12:04:09 PM5/10/13
to watir-...@googlegroups.com
Thanks Andrew!  You learn something new everyday!

Andrew Leaf

unread,
May 10, 2013, 12:15:29 PM5/10/13
to watir-...@googlegroups.com
You're welcome, however, I had a copy and paste failure there.  

browser = Watir::Browser.start url

is the same as

browser = Watir.new 
browser.goto url

Andrew Leaf

unread,
May 10, 2013, 12:16:40 PM5/10/13
to watir-...@googlegroups.com
One last correction:

browser = Watir::Browser.start url
is the same as
browser = Watir::Browser.new 
browser.goto url

Reply all
Reply to author
Forward
0 new messages