Accept/bypass cookies with Selenium

Issue

I’m trying to get a screen shot from of a website from an url
however how can I accept the cookies before the screen shot ?
If you have any idea or clue I will appreciate.

Here is a following picture example of cookies :

enter image description here

Here is my code:

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
start = time.time()

browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://candidat.pole-emploi.fr/offres/recherche/detail/136LNXS/")
browser.save_screenshot('screenshot1.png')

browser.quit()
end = time.time()
print("tempo =","\t",end - start)

Solution

You have to click on accept-button to accept cookie

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

#from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
#chrome to stay open
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
driver.get('https://candidat.pole-emploi.fr/offres/recherche/detail/136LNXS')

WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="footer_tc_privacy_button_2"]'))).click()

Answered By – F.Hoque

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published