seleniumbase / SeleniumBase

📊 Blazing fast Python framework for web crawling, scraping, testing, and reporting. Supports pytest. Stealth abilities: UC Mode and CDP Mode.
https://seleniumbase.io
MIT License
5.44k stars 983 forks source link

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

Closed JonasZaoui2 closed 2 months ago

JonasZaoui2 commented 2 months 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 2 months 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 2 months 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 2 months ago

To delete all cookies:

driver.delete_all_cookies()
JonasZaoui2 commented 2 months ago

To delete all cookies:

driver.delete_all_cookies()

Not working ...

mdmintz commented 2 months 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 2 months 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 2 months 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/