Re: Looking for click_no_wait functionality/solution for Browser.alert

54 views
Skip to first unread message

Ankita@Adslot

unread,
May 9, 2013, 9:59:05 PM5/9/13
to watir-...@googlegroups.com
How about using 
browser.alert.wait_while_present

this will wait for the next line of code to execute until alert goes away

On Friday, May 10, 2013 5:42:54 AM UTC+10, dubsbox wrote:
I'm testing a home-grown shopping cart application which has scenarios where adding an item to the cart results in an alert pop-up appearing.  Scenarios that have just a single alert pop-up can be handled with Browser.alert.ok.  I have run into a couple of scenarios where adding an item to the cart results in multiple consecutive alert pop-ups that need to be cleared.  The first alert can be cleared just fine with Browser.alert.ok.  I am then unable to clear the second alert pop-up.  Working this scenario in irb, I see that after issuing the first Browser.alert.ok command, the irb prompt is not returned.  It seems like the second alert pop-up is blocking progress similar to when an alert pop-up is triggered by clicking a button with just .click instead of .click_no_wait.  So, I'm wondering if anyone has run into a similar situation and has a solution.  It looks like there is no .click_no_wait method defined for the alert pop-ups.

For reference, my successful scenarios look like this:

browser.button(:value,"Add To Cart").click_no_wait     # This triggers the alert pop-up.
($browser.wait_until(10) { $browser.alert.exists? }) ? ($browser.alert.ok) : ()     # Wait a bit and if alert pop-up exists, click OK.  No additional alert pop-up appears.

My unsuccessful scenarios are when an additional alert pop-up appears after clicking OK on the first alert pop-up.

Thanks.

Johnathan



dubsbox

unread,
May 10, 2013, 3:19:39 PM5/10/13
to watir-...@googlegroups.com
Thank you for the response, Ankita.  Unfortunately, it appears that using the browser.alert.wait_while_present does not help me move forward to close out the second alert pop-up.  Rather, it achieves the same result of "hanging" my script when the second pop-up appears.  This makes sense as wait_while_present does the following: "Wait while element is present before continuing."  What I'm looking for is the opposite - no waiting while the element is present before continuing.

Jarmo Pertman

unread,
May 10, 2013, 4:39:04 PM5/10/13
to watir-...@googlegroups.com
You could overwrite the alert function in JavaScript before triggering the first alert. Something like this:
browser.execute_script "window.alert = function() {}"

Jarmo Pertman
-----
IT does really matter - http://itreallymatters.net

ikeonoh

unread,
May 15, 2013, 4:01:34 PM5/15/13
to watir-...@googlegroups.com
I had a similar situation and i jusy repeated the same think twice. Something like:
 
When /^i add me to the cart$/ do
browser.alert.ok
browser.alert.ok
end

Chuck van der Linden

unread,
May 15, 2013, 5:38:40 PM5/15/13
to watir-...@googlegroups.com
Has anyone considered not using JS alerts, in favor of a HTML based solution that does a 'modal alert'  I know there's a bunch of them in Jquery and other handy libraries.  Those are a LOT easier to work with. 
Reply all
Reply to author
Forward
0 new messages