How to check if an alert is present on a page with JavaScript or Selenium How to check if an alert is present on a page with JavaScript or Selenium selenium selenium

How to check if an alert is present on a page with JavaScript or Selenium


You can disable alerts with:

window.alert = () => false

from python that's:

driver.execute_script("window.alert = () => false")


Use :

prefs.setIntPref("permissions.default.desktop-notification",  1);


Assume one is present on the exception of a non located element within a try/catch block, then try to use

driver.switchTo().alert().dismiss();

to proceed with the entended behavior :)