Reputation: 113
I have been looking around stackoverflow and I cannot find a solution to this. The solutions I did find were apparently old.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
This is the error I get
Traceback (most recent call last):
File "C:\Users\amete\Documents\Python\Code\Web test.py", line 10, in <module>
driver = webdriver.Chrome(chrome_options=chrome_options)
File "C:\Users\amete\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\amete\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = r"C:\Users\amete\Documents\chromedriver.exe"
driver = webdriver.Chrome(PATH)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/")
print (driver.title)
search = driver.find_element_by_id("input")
search.send_keys("One Piece")
search.send_keys(Keys.RETURN)
time.sleep(5)
driver.quit()
Upvotes: 3
Views: 2765
Reputation: 29362
Everything looks okay, but the error says chromedriver' executable needs to be in PATH
, right ?
Which means instead of :
driver = webdriver.Chrome(chrome_options=chrome_options)
you need to do this :
driver = webdriver.Chrome(executable_path = PATH, chrome_options=chrome_options)
should work for you.
Upvotes: 1
Reputation: 13
To block all the cookies
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.cookies", 2);
To block all the third party cookies
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.cookies", 1);
options.AddUserProfilePreference("profile.cookie_controls_mode", 1);
Upvotes: 0