Issue
While running automation tests, the expected browser alert does not appear in Firefox, even though it works in other browsers.
Root Cause
In Firefox, the preference dom.disable_beforeunload is set to true by default.
This blocks beforeunload alerts from being displayed.
Solution
You need to explicitly set the Firefox preference dom.disable_beforeunload to false before launching the browser.
Example (Katalon + Selenium):
String browser = DriverFactory.getExecutedBrowser().getName();
if (browser.equalsIgnoreCase(âFIREFOX_DRIVERâ)) {
System.setProperty(âwebdriver.gecko.driverâ,
DriverFactory.getGeckoDriverPath());
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addPreference("dom.disable_beforeunload", false);
WebDriver driver = new FirefoxDriver(firefoxOptions);
driver.navigate().to(url);
DriverFactory.changeWebDriver(driver);
} else {
WebUI.openBrowser(url);
}
Important Note
Setting this via Desired Capabilities in Katalon does not work for Firefox, because the FirefoxDriver constructor only accepts FirefoxOptions.
Takeaway
If Firefox alerts are not appearing:
- Check the
dom.disable_beforeunloadpreference - Use
FirefoxOptionsinstead of Desired Capabilities
Hope this helps anyone facing the same issue ![]()
Enjoy testing