How Supress UnhandledAlertException for Modal dialog box

23,047 views
Skip to first unread message

Jakes

unread,
Jan 31, 2012, 3:42:09 PM1/31/12
to webdriver
New in Selenium 2.18.. Whenever alert or Modal dialog box is displayed
in browser UnhandledAlertException is thrown. Before version 2.18 I
was able to get the driver switch to the modal window using
driver.getWindowHandles(). But with the new 2.18 release build it's
causing the scripts to fail. I can understand if it's done only for
alert message.
But throwing the UnhandledAlertException same for Modal dialog box
cause the problem since the test cases need complete few operations in
the modal dialog box window before clicking OK. This
UnhandledAlertException prevents us to any operation in the modal
dialog box window. Can some one suggest a work around for this or is
this bug?

org.openqa.selenium.UnhandledAlertException: Modal dialog present
(WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
Build info: version: '2.18.0', revision: '15704', time: '2012-01-27
15:49:22'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version:
'6.1', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:
147)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:
118)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
439)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
443)
at
org.openqa.selenium.remote.RemoteWebDriver.getWindowHandles(RemoteWebDriver.java:
327)
at
com.automation.paf.actions.BrowserActionSwitchToWindow.SwitchToWindow(BrowserActionSwitchToWindow.java:
106)
at
com.automation.paf.actions.BrowserActionSwitchToWindow.TrySwitch(BrowserActionSwitchToWindow.java:
75)
at
com.automation.paf.actions.BrowserActionSwitchToWindow.Execute(BrowserActionSwitchToWindow.java:
46)
at com.automation.paf.TestRunner.run(TestRunner.java:62)
at com.automation.paf.TestRunner.RunBrowserActions(TestRunner.java:
122)
at com.automation.paf.PAFTest.run(PAFTest.java:169)
at java.lang.Thread.run(Unknown Source)

Daniel Wagner-Hall

unread,
Jan 31, 2012, 7:11:20 PM1/31/12
to webd...@googlegroups.com
driver.switchTo().alert()

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

Jakes

unread,
Jan 31, 2012, 8:27:44 PM1/31/12
to webdriver
I tried driver.switchTo().alert() too.. I am getting the same
UnhandledAlertException when a modal window dialog box is displayed.

On Jan 31, 4:11 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> driver.switchTo().alert()
>

Pavithra

unread,
Feb 1, 2012, 12:07:25 PM2/1/12
to webdriver

I faced similar issue. I resolved using autoit before executing switch
to window . If your alert can be suppressed by sending escape or enter
you can write autoit to send enter or escape key and then call
switchtowindow with some sleeps inbetween. This worked out for me.

Jakes

unread,
Feb 2, 2012, 2:07:49 PM2/2/12
to webdriver
This was feature what was working fine. Now, I have to write autoIt in
innumerous modal window dialog box. I am not happy :)

On Feb 1, 9:07 am, Pavithra <pavi...@gmail.com> wrote:
> I faced similar issue. I resolved using autoit before executing switch
> to window . If your alert can be suppressed by sending escape or enter
> you can write autoit to send enter or escape key and then call
> switchtowindow with some sleeps inbetween. This worked out for me.
>
> On Feb 1, 6:27 am, Jakes <jragha...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I tried driver.switchTo().alert() too.. I am getting the same
> >UnhandledAlertExceptionwhen a modal window dialog box is displayed.
>
> > On Jan 31, 4:11 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
>
> > > driver.switchTo().alert()
>
> > > On 31 January 2012 20:42, Jakes <jragha...@gmail.com> wrote:
>
> > > > New in Selenium 2.18.. Whenever alert or Modal dialog box is displayed
> > > > in browserUnhandledAlertExceptionis thrown. Before version 2.18 I
> > > > was able to get the driver switch to the modal window using
> > > > driver.getWindowHandles(). But with the new 2.18 release build it's
> > > > causing the scripts to fail. I can understand if it's done only for
> > > > alert message.
> > > > But throwing theUnhandledAlertException same for Modal dialog box
> > > > cause the problem since the test cases need complete few operations in
> > > > the modal dialog box window before clicking OK. This
> > > >UnhandledAlertExceptionprevents us to any operation in the modal

Jim Evans

unread,
Feb 2, 2012, 2:59:03 PM2/2/12
to webdriver
Guys, this was due to some overzealous changes in 2.18.0 to throw an
exception when an alert is not handled. Unfortunately, when the
feature was implemented, it didn't take showModalDialog() windows into
account. I have corrected that problem in the current sources[1], and
a fix will be forthcoming in the next binary release. In the meantime,
you can downgrade to 2.17.0 until the next release to work around the
problem.

--Jim

[1] http://code.google.com/p/selenium/source/detail?r=15807

James Davis

unread,
Feb 9, 2012, 5:10:56 PM2/9/12
to webdriver
Hello,

I am receiving the same error as discussed in
http://groups.google.com/group/webdriver/browse_thread/thread/68dc8e7c48cc10d8.
Revision 15807 fixed the cause of this error so I installed version
2.19.0. With 2.19.0 I am still getting the "UnhandledAlertException
for Modal dialog box" when I get the alert text and accept it.

public String getAlert() {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText().trim();
alert.accept();
return alertText;
}

The above code works great with version 2.17.0 (as Jim Evans
suggested).

Is there a ticket open for this issue? I checked issues and could not
find one/ I ask because I would like to monitor when the fix is
released to production so I can upgrade to the appropriate build. Or
do I have to download the 2.19.0 IE driver separately? Unfortunately
it is a show-stopper for our team.

Sincerely,

James Davis

Rune

unread,
Feb 28, 2012, 10:14:39 AM2/28/12
to webdriver
I have the exact same problem in 2.19.0. Please fix it!

Alert alert = driver.switchTo().alert();

[cucumber] [31m org.openqa.selenium.UnhandledAlertException:
Modal dialog present (WARNING: The server did not provide any
stacktrace information) [0m
[cucumber] [31m Command duration or timeout: 24
milliseconds [0m
[cucumber] [31m Build info: version: '2.19.0', revision:
'15849', time: '2012-02-08 16:10:57' [0m
[cucumber] [31m System info: os.name: 'Windows 7', os.arch:
'x86', os.version: '6.1', java.version: '1.6.0_29' [0m
[cucumber] [31m Driver info: driver.version:
EventFiringWebDriver [0m
[cucumber] [31m Build info: version: '2.19.0', revision:
'15848', time: '2012-02-08 16:25:03' [0m
[cucumber] [31m System info: os.name: 'Linux', os.arch:
'amd64', os.version: '2.6.32-37-server', java.version: '1.6.0_26' [0m
[cucumber] [31m Driver info: driver.version: RemoteWebDriver
(NativeException) [0m

Jim Evans

unread,
Feb 28, 2012, 12:40:17 PM2/28/12
to webdriver
Awfully demanding tone, there Rune. My time to devote to the IE driver
has become very limited. I'll get to it as soon as I can, but will
gratefully accept patches, if someone else wants to take a crack at
it.

--Jim

Jim Evans

unread,
Feb 28, 2012, 12:46:47 PM2/28/12
to webdriver
James, forgive me as I'm a little confused here. Can you give me a
little more context as to what the issue actually is? It sounds like
we're talking about two different things here. Are you still receiving
UnhandledAlertExceptions when you encounter a showModalDialog()
window? Are you receiving the exception after you've properly handled
an alert?

--Jim

On Feb 9, 5:10 pm, James Davis <mountain1...@gmail.com> wrote:
> Hello,
>
> I am receiving the same error as discussed inhttp://groups.google.com/group/webdriver/browse_thread/thread/68dc8e7....

ssimmons

unread,
Mar 3, 2012, 1:15:53 PM3/3/12
to webdriver
Not sure if this will help, but I am dealing with this issue also and
it may be related to issue 3360 in which trying to launch an IE driver
with IE developer tools open immediately throws this exception. I've
also encountered this exception in IE when a certificate selection
screen pops up. Both of these situations worked in the previous
Selenium version I was using (2.16)

On Feb 28, 12:46 pm, Jim Evans <james.h.evans...@gmail.com> wrote:
> James, forgive me as I'm a little confused here. Can you give me a
> little more context as to what the issue actually is? It sounds like
> we're talking about two different things here. Are you still receiving
> UnhandledAlertExceptions when you encounter a showModalDialog()
> window? Are you receiving the exception after you've properly handled
> an alert?
>
> --Jim
>
> On Feb 9, 5:10 pm, James Davis <mountain1...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I am receiving the same error as discussed inhttp://groups.google.com/group/webdriver/browse_thread/thread/68dc8e7....
> > Revision 15807 fixed the cause of this error so I installed version
> > 2.19.0. With 2.19.0 I am still getting the "UnhandledAlertException
> > forModaldialog box" when I get the alert text and accept it.

Leonardo Galani

unread,
Mar 7, 2012, 6:42:43 PM3/7/12
to webd...@googlegroups.com
Almost same issue here..

the "UnhandledAlertException" is closing the alert / modal BEFORE i take a screenshot of the full page.
Alerts appears on my app when something went wrong.. so i dont need to "handle" the alert... if it pops.. the script breaks and take a printscreen..
before the UnhandledAlertException it was working fine..  but now im using 2.20 and this messing up my tests :(

The funny thing is.. its  also throwing this exception on the "unsucess handler" .. lolz..  omg!

Btw,.. also using IE driver.
Message has been deleted

James Davis

unread,
Mar 8, 2012, 9:24:08 AM3/8/12
to webdriver
Jim this was my bad. I had overridden the click function to check the
browser title for an error condition. Because the modal dialog was
present, WebDriver could not read the title thus the
UnhandledAlertException exception was thrown (working as
designed!! :) ).

Here is the code

WebElement e = driver.findElement(By.id("mybutton"));
e.click(); // This action loads a modal window that is not handled

// Check title for error condition. At this point the
UnhandledAlertException was thrown because the modal dialog.window was
not being handled.
String title = driver.getTitle();

False negative on my part, also I was seeing this issue with FF 10 and
not IE. Sorry for the confusion.

Sincerely,

James Davis

s_kittu

unread,
Mar 9, 2012, 8:23:36 AM3/9/12
to webd...@googlegroups.com
Jakes

I have seen the same issue when IE pops up a dialog asking to remember  the username or password or not. So, i have overcome this by clearing a check box 'Usernames and password on forms'  under tools->options->content->autocomplete->settings.

Hope this helps you.

Manoj

unread,
Mar 26, 2012, 12:10:55 PM3/26/12
to webdriver
Anyone any idea about how to handle alert which is present on modal
dialog popup???
I tried every command like selenium.getalert(),
driver.switchto().alert().accept(), sendkeys(Keys.Enter or Space) but
no luck.
Is this bug??



On Mar 8, 7:24 pm, James Davis <mountain1...@gmail.com> wrote:
> Jim this was my bad. I had overridden the click function to check the
> browser title for an error condition. Because themodaldialogwas
> present, WebDriver could not read the title thus the
> UnhandledAlertException exception was thrown (working as
> designed!! :) ).
>
> Here is the code
>
> WebElement e = driver.findElement(By.id("mybutton"));
> e.click();  // This action loads amodalwindow that is not handled
>
> // Check title for error condition. At this point the
> UnhandledAlertException was thrown because themodaldialog.window was

sai krishna

unread,
Jul 12, 2012, 6:31:57 AM7/12/12
to webd...@googlegroups.com
Hi 

i have scenario where clicking on some link in parent window  opens a new window, after performing the actions on the child window, iam unable get back focus on the parent window , i have used the command driver.switchTo().window(parentWindowHandle) where parentWindowHandle is the window handler of parent window.
i have also used the seleniumwebdriver backed command selectWindow(parentWindowHandle)
iam getting the error 

org.openqa.selenium.WebDriverException: 'auto_id' does not refer to an open tab (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0-ea'
Driver info: driver.version: ChromeDriver
Command duration or timeout: 31 milliseconds
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0-ea'
Driver info: driver.version: TafRemoteWebDriver
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:463)
	at com.socialtwist.taf.webdriver.TafRemoteWebDriver.getScreenshotAs(TafRemoteWebDriver.java:22)
	at com.socialtwist.taf.selenium.TafSelenium.screenShot(TafSelenium.java:1008)
	at com.socialtwist.taf.testnghelpers.CustomTestListener.afterInvocation(CustomTestListener.java:36)
	at org.testng.internal.invokers.InvokedMethodListenerInvoker$InvokeAfterInvocationWithoutContextStrategy.callMethod(InvokedMethodListenerInvoker.java:100)
	at org.testng.internal.invokers.InvokedMethodListenerInvoker.invokeListener(InvokedMethodListenerInvoker.java:62)
	at org.testng.internal.Invoker.runInvokedMethodListeners(Invoker.java:579)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:727)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
	at org.testng.TestRunner.privateRun(TestRunner.java:749)
	at org.testng.TestRunner.run(TestRunner.java:600)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
	at org.testng.SuiteRunner.run(SuiteRunner.java:223)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1049)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:974)
	at org.testng.TestNG.run(TestNG.java:905)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:203)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
Caused by: org.openqa.selenium.WebDriverException: 'auto_id' does not refer to an open tab (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0-ea'
Driver info: driver.version: ChromeDriver
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0-ea'
Driver info: driver.version: ChromeDriver
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:175)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:128)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:459)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:463)
	at org.openqa.selenium.chrome.ChromeDriver.getScreenshotAs(ChromeDriver.java:149)
	at org.openqa.selenium.remote.server.handler.CaptureScreenshot.call(CaptureScreenshot.java:36)
	at org.openqa.selenium.remote.server.handler.CaptureScreenshot.call(CaptureScreenshot.java:1)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:151)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)


But the same is working in firefox browser.

iam using selenium-standalone-server-2.24.1.jar and chrome driver20 on windows machine
please help

Thanks
Saikrishna

On Wednesday, 1 February 2012 02:12:09 UTC+5:30, Jakes wrote:

Michael

unread,
Sep 6, 2012, 11:03:55 AM9/6/12
to webd...@googlegroups.com
With version 2.25 it didn't work out,
after switching back to 2.23.1 it worked quite well

Umamaheshwar Thota

unread,
Feb 28, 2013, 2:57:59 AM2/28/13
to webd...@googlegroups.com
Hi Nitin Rajpal,

Are you able to take the screen shot of the alert now. If so, please share the code for the same.

Cheers,
Umamaheshwar Thota

On Thursday, October 18, 2012 11:17:23 AM UTC+5:30, Lolz ha ha ha wrote:
Hi,

Thank You for the information, Please inform that is this issue fixed in 2.25.0 Java. I am facing the issue of not able to take screen shot of alert.

Thank you
Nitin Rajpal
Reply all
Reply to author
Forward
0 new messages