Waiting until alert/confirm/prompt is shown

2,031 views
Skip to first unread message

Jackie Ng

unread,
Sep 17, 2015, 2:43:04 AM9/17/15
to NightwatchJs
Hi All,

Does nightwatch offer the ability to wait until an alert/confirm/prompt dialog is shown?

I see there are selenium commands to interact with alert dialogs, but how does one know if/when such a dialog is showing for selenium to interact with it?

- Jackie

Andrei Rusu

unread,
Sep 17, 2015, 3:44:21 AM9/17/15
to nightw...@googlegroups.com
As far as I'm aware it's not possible to check for an alert if it's
present but you can try to use .getAlertText() and presumably it will
give you an error in the result if it's not present:
http://nightwatchjs.org/api#getAlertText

And about waiting I suggest to write a custom command, for instance
something like this:
https://github.com/nightwatchjs/nightwatch/issues/246.
> --
> You received this message because you are subscribed to the Google Groups
> "NightwatchJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nightwatchjs...@googlegroups.com.
> To post to this group, send email to nightw...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nightwatchjs/ee72996b-5997-4138-b7b0-ea652e6d2ac7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Piotr Sobczyk

unread,
Dec 4, 2015, 11:41:53 AM12/4/15
to NightwatchJs
Unfortunately in my case getAlertText doesn't break the test if there is no dialog open. Response status from the Selenium server is 500 and I can see the error message when I run nightwatch with --verbose flag, yet the test is still successful. The same problem with acceptAlert() (and with the even with the plain click(), if element cannot be clicked, for that matter).

Bao.Tran

unread,
Jun 3, 2016, 5:40:02 AM6/3/16
to NightwatchJs
Do we have it now,function .waitForAlertPresent() ?

Eric Mumford

unread,
Jun 7, 2016, 12:04:28 AM6/7/16
to NightwatchJs
Do you want code to execute if an alert is shown, do you want code to execute if an alert is not present, do you want an independent watchdog code to trigger an event if a modal is ever shown..? Your question is imprecise.

John Kretschmann

unread,
Feb 3, 2021, 7:55:31 PM2/3/21
to NightwatchJs
Wow, I'm coming along on this issue a few years later!  Still no answer it seems.  As far as I can tell, there is no .waitForAlertPresent() function.  I tried using getAlertText() and it will return status: -1 if the alert is not found.  However, it will also throw an error message to the console which is not desirable.
Reply all
Reply to author
Forward
0 new messages