Selenium test - Firefox alert disappearing immediately

Viewed 2701

I am writing a Selenium test on Firefox that deals with an alert. The alert appears for a fraction of a second when the test is run, but when done manually the alert persists. Can anyone tell why this is the case?

I tried setting this profile on Firefox, but that did not help either:

profile.setPreference("alerts.disableSlidingEffect", true);

Can anyone tell how I can make the alert stay on the page?

In the code, I am checking the presence of the alert as this, which apparently is never getting hit since the alert is disappearing too quick:

WebDriverWait wait = new WebDriverWait(webDriver, Long.parseLong(parameters[0]));
wait.until(ExpectedConditions.alertIsPresent());
3 Answers

The chosen answer worked for me, but it seems that FirefoxDriver(org.openqa.selenium.Capabilities) is deprecated. The working alternative is:

FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
driver = new FirefoxDriver(firefoxOptions);
Related