How can I remove notifications and warnings from the browser? selenium python 2.7.7

I am trying to send information to a web page, but selenium is causing this error:

UnexpectedAlertPresentException: Warning text: this page asks you to confirm that you want to leave - the data you entered may not be saved.,>

This is not an exit notice; here is the notification photo -

enter image description here .

If I click, I will never show this notification, my action will not be saved; Is there a way to save or disable all notifications?

edit: I am using firefox.

+2
source share
2 answers

You can turn off browser notifications using the chrome options. Sample code below:

chrome_options = webdriver.ChromeOptions() prefs = {"profile.default_content_setting_values.notifications" : 2} chrome_options.add_experimental_option("prefs",prefs) driver = webdriver.Chrome(chrome_options=chrome_options) 
+13
source

Usually with browser settings like this, any changes you make will be discarded the next time Selenium launches a new browser instance.

Do you use a special Firefox profile to run selenium tests? If so, in this Firefox profile, set this option the way you want, and then close the browser. This should properly save it for later use. You will need to tell Selenium to use this profile, although this is done by SetCapabilities when starting a driver session.

+2
source

Source: https://habr.com/ru/post/1013282/


All Articles