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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With