Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i remove notifications and alerts from browser? selenium python 2.7.7

I am trying to submit information in a webpage, but selenium throws this error:

UnexpectedAlertPresentException: Alert Text: This page is asking you to confirm that you want to leave - data you have entered may not be saved. , >

It's not a leave notification; here is a pic of the notification -

enter image description here.

If I click in never show this notification again, my action doesn't get saved; is there a way to save it or disable all notifications?

edit: I'm using firefox.

like image 779
2one2 Avatar asked Nov 27 '22 23:11

2one2


2 Answers

You can disable the browser notifications, using 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)
like image 54
TH Todorov Avatar answered Dec 05 '22 03:12

TH Todorov


With the latest version of Firefox the above preferences didn't work.

Below is the solution which disable notifications using Firefox object

_browser_profile = webdriver.FirefoxProfile()
_browser_profile.set_preference("dom.webnotifications.enabled", False)
webdriver.Firefox(firefox_profile=_browser_profile)

Disable notifications when using Remote Object: webdriver.Remote(desired_capabilities=_desired_caps, command_executor=_url, options=_custom_options, browser_profile=_browser_profile)

selenium==3.11.0

like image 28
Anvesh Avatar answered Dec 05 '22 03:12

Anvesh