mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.19k stars 1.52k forks source link

Block permission notifications for desktop-notifications (facebook) #1243

Open najbot opened 6 years ago

najbot commented 6 years ago

I would like help please. I use selenium with the python language.

I created a robot to explore the facebook site. The problem is that from a few seconds I have the chromewebdriver window that remains frozen I have to click myself with my mouse to remove the blockage.

So it's really not helpful if I have to use selenium because the bot can not find the site's selectors which shows me errors.

If you can test on facebook.com and see if after a few seconds the browser remains frozen?

On all sites I have no problem

whimboo commented 6 years ago

Please note that this repository is for the geckodriver which drives Firefox and has nothing to do with the chromewebdriver. Please use the appropriate repository to file issues.

najbot commented 6 years ago

Hello, sorry but this is also happening with firefox so the problem remains the same. It is a notification which blic the page and which asks to validate by yes or no. So as the webdriver does not know how to do action on the windows window so the lock is permanent.

On the other hand I found the solution for those who are on firefox or chrome must disable notifications from the options of geckodriver or chrome:

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)

We just have to adapt it for geckodriver

Donc

whimboo commented 6 years ago

Please provide a trace log for that test. Make sure that remove credentials in case you have to login. I'm not sure what you mean with notifications here, maybe attach a screenshot too.

najbot commented 6 years ago

@whimboo https://stackoverflow.com/questions/38684175/how-to-click-allow-on-show-notifications-popup-using-selenium-webdriver

whimboo commented 6 years ago

Hm, can you have a look at https://support.mozilla.org/en-US/questions/1193258? Does the All-Site Persistent Disable suggestion work for you?

gumdropsteve commented 6 years ago

Was this ever sorted? Trying to do this now. Thanks.

andreastt commented 6 years ago

I think we need to confirm which Firefox preference turns them off.

andreastt commented 6 years ago

@whimboo On further reflection, why do we want to turn off notifications? As I understand it, they are not detrimental to WebDriver performance or behaviour, and if there is a pref, users can turn them off when unwanted.

najbot commented 6 years ago

@whimboo On further reflection, why do we want to turn off notifications? As I understand it, they are not detrimental to WebDriver performance or behaviour, and if there is a pref, users can turn them off when unwanted.

Hi, it was for my problem. Because on facebook there is a notification that asks to click on ok. As long as I have this window the webdriver remains blocked and generates an error. By adding the code above this could disable the notification and my bot can continue to run.

gumdropsteve commented 6 years ago

@whimboo On further reflection, why do we want to turn off notifications? As I understand it, they are not detrimental to WebDriver performance or behaviour, and if there is a pref, users can turn them off when unwanted.

Hi, it was for my problem. Because on facebook there is a notification that asks to click on ok. As long as I have this window the webdriver remains blocked and generates an error. By adding the code above this could disable the notification and my bot can continue to run.

Same. Using Firefox/Geckodriver.

I have made a script that posts to my page after I feed in an input, but after it logs into Facebook the "Will you allow Facebook.com to send you notifications?" pops up and I have to manually hit escape (to just ignore it) or "yes" or "no".

Whether or not it sends notifications is not the issue, the issue is getting past the pop up prompt.

Thank you.

whimboo commented 6 years ago

Ok, can someone please take a screenshot so that it is clear about which notification we talk about? As it looks like we might write past each other.

najbot commented 6 years ago

Ok, can someone please take a screenshot so that it is clear about which notification we talk about? As it looks like we might write past each other.

For me it was this notification window

whimboo commented 6 years ago

Ok, so that is clearly blocking the UI interaction in content as long as it is open. It's similar to the add-on install permission notification.

So does setting the preference as referenced in https://support.mozilla.org/en-US/kb/push-notifications-firefox#w_how-do-i-disable-web-push-completely work?

najbot commented 6 years ago

my solution for chrome: 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)

it works for me but with firefox I can not help but it's already a track

gumdropsteve commented 6 years ago

my solution for chrome: 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)

it works for me but with firefox I can not help but it's already a track

@najbot Would you recommend I just switch to Chrome? (Taking it you were never able to find solution for Firefox?). Thanks.

@whimboo please see attached snip (below). It's still able to login, load my page, locate the status element and send keys without needing to get rid of the notification, but it can not post. End goal is to have it auto-posting updates of new listings (real estate) when the listings are first loaded onto my website. Here is my code for this part of the project (first repository & self-taught, so probably easily roast-able): https://github.com/gumdropsteve/posttopage-facebook . Thanks.

capture

Thank you for all your help.

najbot commented 6 years ago

my solution for chrome: 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) it works for me but with firefox I can not help but it's already a track

@najbot Would you recommend I just switch to Chrome? (Taking it you were never able to find solution for Firefox?). Thanks.

@whimboo please see attached snip (below). It's still able to login, load my page, locate the status element and send keys without needing to get rid of the notification, but it can not post. End goal is to have it auto-posting updates of new listings (real estate) when the listings are first loaded onto my website. Here is my code for this part of the project (first repository & self-taught, so probably easily roast-able): https://github.com/gumdropsteve/posttopage-facebook . Thanks.

capture

Thank you for all your help.

Yes I recommend it because your concern is exactly like the one I had. So go to chrome because for me the code below works I have more notification. In addition I do not see too much interest to choose firefox.

gumdropsteve commented 6 years ago

my solution for chrome: 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) it works for me but with firefox I can not help but it's already a track

@najbot Would you recommend I just switch to Chrome? (Taking it you were never able to find solution for Firefox?). Thanks. @whimboo please see attached snip (below). It's still able to login, load my page, locate the status element and send keys without needing to get rid of the notification, but it can not post. End goal is to have it auto-posting updates of new listings (real estate) when the listings are first loaded onto my website. Here is my code for this part of the project (first repository & self-taught, so probably easily roast-able): https://github.com/gumdropsteve/posttopage-facebook . Thanks. capture Thank you for all your help.

Yes I recommend it because your concern is exactly like the one I had. So go to chrome because for me the code below works I have more notification. In addition I do not see too much interest to choose firefox.

Cheers, thanks

ADDITIONAL/EDIT: at which point in the code do you recommend pasting this? Thanks. ( EDIT: Figured it out, just replaced original line bringing in driver, for example (future people) see code here: https://github.com/gumdropsteve/posttopage-facebook )

NEW ISSUE: Geckodriver supports characters out of the BMP (e.g. emojis) but Chromedriver does not. If anyone knows how to get around this or has found the disable notifications fix for Geckodriver please let me know. Thanks.

whimboo commented 6 years ago

@gumdropsteve, I don't suggest just to switch to Chrome for testing when you actually want to test your pages in basically all browsers. So I don't even understand why this was suggested by @najbot. Sorry, but that is a poor decision.

Instead see https://github.com/mozilla/geckodriver/issues/1243#issuecomment-426990457. The referenced support page lists two preferences you want to set to false before creating the session. Those preferences are:

gumdropsteve commented 6 years ago

@gumdropsteve, I don't suggest just to switch to Chrome for testing when you actually want to test your pages in basically all browsers. So I don't even understand why this was suggested by @najbot. Sorry, but that is a poor decision.

Instead see #1243 (comment). The referenced support page lists two preferences you want to set to false before creating the session. Those preferences are:

* dom.webnotifications.enabled

* dom.push.enabled

Once done you should no longer see the permission notification pop-ups to appear.

Brilliant, thank you. Working on an email format right now but will get to this in next few days and update this response. Thank you!