seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.36k stars 979 forks source link

How disable notifications ? (popups, cookies ...) #3151

Closed JonasZaoui2 closed 1 month ago

JonasZaoui2 commented 1 month ago

Hello ! I want to disable notifications, I tried this command

from seleniumbase import Driver

self.driver = Driver(
            browser = 'chrome',
            uc=True,
            headless=True,
            chromium_arg="--disable-extensions, --disable-gpu, --disable-dev-shm-usage, --disable-notifications, --hide-scrollbars, --disabled-new-style-notification, --allow-silent-push"
        )

But it's not working ... I tried on this URL : https://www.nvidia.com/fr-fr/

mdmintz commented 1 month ago

Notifications are already disabled by default:

https://github.com/seleniumbase/SeleniumBase/blob/d4e52465d13960957f26c6c02d04944cea4a6987/seleniumbase/core/browser_launcher.py#L1961

On the website you showed me, the part at the bottom is not an official browser "notification":

Screenshot

(The part on the bottom is part of the website.)

When notifications are disabled, that part will still show up.

You'll have to interact with it to remove it:

driver.click("#onetrust-accept-btn-handler")

JonasZaoui2 commented 1 month ago

Thanks for your feedback! In fact, I'll need to remove cookies regardless of the url given (for all sites). Is there a solution?

Capture d’écran 2024-09-20 à 14 47 21
mdmintz commented 1 month ago

To delete all cookies:

driver.delete_all_cookies()
JonasZaoui2 commented 1 month ago

To delete all cookies:

driver.delete_all_cookies()

Not working ...

mdmintz commented 1 month ago

driver.delete_all_cookies() comes directly from raw Selenium: https://github.com/SeleniumHQ/selenium/blob/030fcf79186e5597269166bd8dfa888e1eda29d7/py/selenium/webdriver/remote/webdriver.py#L614

JonasZaoui2 commented 1 month ago

Thanks ! I tried but it's not working. But i have just found a solution with Selenium,

  chrome_options.add_experimental_option("prefs", {
            "profile.default_content_setting_values.cookies": 2
        })

It's possible with SeleniumBase ?

mdmintz commented 1 month ago

To disable cookies, upgrade to SeleniumBase 4.31.2 (or newer) and use --disable-cookies / disable_cookies=True

JonasZaoui2 commented 1 month ago

Thanks ! But it can't deal with cookies at the bottom of the website right ? Like here : https://soundcloud.com/