Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal dialog present Exception

I try to click on a element, by this way:

WebElement title = driver.findElement(By.xpath("//a[text()=\"Delete this document library\"]"));
title.click();

When I click on it manually, its opens a window:

The page at http://.. says
Are you sure you want to delete the selected items?

with OK and Cancel buttons

But when I run it with WebDriver (in Firefox 20.0), I get the next error:

[Exception]: Modal dialog present

and I don't see even the window.

What can be the reason?

like image 599
user2490373 Avatar asked Feb 16 '23 12:02

user2490373


1 Answers

You don't see the Alert when you run the test is because the default behavior of the WebDriver is that it accepts alert when the Modal dialog present exception is thrown. It happens so fast that you can't see the alert.

  WebElement title = driver.findElement(By.xpath("//a[text()=\"Delete this document library\"]"));
title.click();

//Now the alert appears. 
Alert alert = driver.switchTo().alert();
alert.accept();
like image 152
Code Enthusiastic Avatar answered Feb 20 '23 09:02

Code Enthusiastic