I have been looking around stackoverflow and I cannot find a solution to this. The solutions I did find were apparently old.
JavaScript
x
5
1
chrome_options = webdriver.ChromeOptions()
2
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
3
4
driver = webdriver.Chrome(chrome_options=chrome_options)
5
This is the error I get
JavaScript
1
12
12
1
Traceback (most recent call last):
2
File "C:UsersameteDocumentsPythonCodeWeb test.py", line 10, in <module>
3
driver = webdriver.Chrome(chrome_options=chrome_options)
4
File "C:UsersameteAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdriverchromewebdriver.py", line 73, in __init__
5
self.service.start()
6
File "C:UsersameteAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdrivercommonservice.py", line 81, in start
7
raise WebDriverException(
8
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
9
10
11
Process finished with exit code 1
12
My code:
JavaScript
1
21
21
1
from selenium import webdriver
2
from selenium.webdriver.common.keys import Keys
3
import time
4
PATH = r"C:UsersameteDocumentschromedriver.exe"
5
driver = webdriver.Chrome(PATH)
6
7
chrome_options = webdriver.ChromeOptions()
8
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
9
10
driver = webdriver.Chrome(chrome_options=chrome_options)
11
12
driver.get("https://www.google.com/")
13
print (driver.title)
14
15
search = driver.find_element_by_id("input")
16
search.send_keys("One Piece")
17
search.send_keys(Keys.RETURN)
18
19
time.sleep(5)
20
driver.quit()
21
Advertisement
Answer
Everything looks okay, but the error says chromedriver' executable needs to be in PATH
, right ?
Which means instead of :
JavaScript
1
2
1
driver = webdriver.Chrome(chrome_options=chrome_options)
2
you need to do this :
JavaScript
1
2
1
driver = webdriver.Chrome(executable_path = PATH, chrome_options=chrome_options)
2
should work for you.