Re: While running a selenium test script, I am not able to handle the "Modal dialog box" .

518 views
Skip to first unread message

Mike Riley

unread,
Apr 22, 2013, 4:30:00 PM4/22/13
to seleniu...@googlegroups.com
You need to use the Alert class to get rid of the dialog.

Mike

On Thursday, April 18, 2013 6:54:45 AM UTC-7, anitashreedhar hegde wrote:
Hi,
 
 

selenium version: 2.25.0

browser used: firefox

System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_31'

Driver info: driver.version: RemoteWebDriver

 
Problem:
------------
 
While running a selenium test script, I am not able to handle the "Modal dialog box" .
 
i.e. when I click on a button, it pops up the Modal dialog box with  OK, Cancel buttons. When I click on Ok button, it takes me into another page.
 
But when I run my script, it just gives me below error:
 
org.openqa.selenium.UnhandledAlertException  : Modal dialog present
 
Also, on the screen I get the pop up window with this message :
 
An AJAX HTTP request terminated abnormally.
Debugging information follows,
Path: /system/ajax
Status Text: error
Response Text:
ReadySate: 0
 
The sample code that I have used in my code is:
----------------------------------------------------------------
 

WebElement button = driver.findElement(By.id("confirm"));

button.click();

try {

//Get the Alert

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

alert.accept();

}

catch (NoAlertPresentException e) {

e.printStackTrace();

}

Regards,

Anita

 

Sel User

unread,
Sep 10, 2013, 5:43:36 AM9/10/13
to seleniu...@googlegroups.com
Hi Anita,
 
Is this problem of yours solved?
 
What is the workaround u used. I am facing this error and it does not come when I do the scenario manually but only while running webdriver.....

ikoe...@gmail.com

unread,
Sep 10, 2013, 4:21:59 PM9/10/13
to seleniu...@googlegroups.com
I am also curious.  I am currently getting the same error when I try to handle a modal popup.  I tried a try-catch statement to handle the exception but it never seems to hit it (the code inside of the catch is never executed).  I found somewhere that this behavior worked correctly in previous versions of Selenium (something like 2.18 and lower).

DongXiang

unread,
Sep 12, 2013, 8:41:08 AM9/12/13
to seleniu...@googlegroups.com

button.click();

try {

//Get the Alert

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


org.openqa.selenium.UnhandledAlertException  : Modal dialog present


I guess ur codes need sleep for a while before handle alert, I guess switchTo().alert() were executed before the real alert dialog popup.


  I am currently getting the same error when I try to handle a modal popup.  I tried a try-catch statement to handle the exception but it never seems to hit it (the code inside of the catch is never executed)


I guess your webdriver were hang when you click button to open the modal dialog, webdriver  will hang when showModalDialog method be invoked. There is another session which has the solution, you can have a look.


--david



Date: Tue, 10 Sep 2013 13:21:59 -0700
From: ikoe...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: While running a selenium test script, I am not able to handle the "Modal dialog box" .
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a42d34bd-0447-454e-ac95-aa904abdf00a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jelensk...@software.com.pl

unread,
Sep 13, 2013, 5:58:32 AM9/13/13
to seleniu...@googlegroups.com
Hi,

Interest in test automation with Selenium 2? http://bit.ly/15ObtZJ

Marilyn Butler

unread,
Sep 17, 2013, 12:36:18 PM9/17/13
to seleniu...@googlegroups.com

I used the following statement:

               driver.switchTo().alert().accept();

I found this statement on http://grokbase.com/t/gg/webdriver/127kzrvxqn/click-on-pop-up-windows

Manoj knew the secret.

Reply all
Reply to author
Forward
0 new messages