RCarmody
RCarmody

Reputation: 720

Python Selenium Chrome Webdriver not installing

I am trying to automatically install the latest version of Chrome Driver and then use that for my script, but am running into errors. Any thoughts as to what's wrong here? Something with my cache?

driver2 = webdriver.Chrome(ChromeDriverManager().install())
options = selenium.webdriver.ChromeOptions()
#options.add_argument('headless')
options.add_argument('window-size=1920x1080')
driver = webdriver.Chrome(driver2, options=options)

Error:

[WDM] - Looking for [chromedriver 89.0.4389.23 win32] driver in cache 
[WDM] - File found in cache by path [C:\Users\xxx\.wdm\drivers\chromedriver\89.0.4389.23\win32\chromedriver.exe]
Traceback (most recent call last):
  File "C:\Users\xxx\Python\Price Tracking\Real Estate\RealEstate-Scraping.py", line 60, in <module>
    driver = webdriver.Chrome(driver2, options=options)
  File "C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.py", line 1247, in _execute_child
    args = list2cmdline(args)
  File "C:\Python38\lib\subprocess.py", line 549, in list2cmdline
    for arg in map(os.fsdecode, seq):
  File "C:\Python38\lib\os.py", line 818, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not WebDriver

Upvotes: 0

Views: 17159

Answers (3)

Vova
Vova

Reputation: 3541

try that out:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

driver.get('https://google.com')

driver.quit()

when you're passing argument options to webdriver, set it above initializing and put it in chrome() like that:

options = Options()
options.add_argument('--headless')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

and initialize driver finally

Upvotes: 0

bobtho&#39;-&#39;
bobtho&#39;-&#39;

Reputation: 168

You need to tell the path of the webdriver:

webdriver.chrome(executable_path=*path*,options=options)

but driver2 = webdriver.Chrome(ChromeDriverManager().install()) creates a new instance of selenium.

driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)

should work with your use case - the 1st line of your code is not necessary.

Please note that the 'headless' needs '--' in front of it, too.

Full code:

options = selenium.webdriver.ChromeOptions()
#options.add_argument('--headless')
#could also do options.headless = True
options.add_argument('--window-size=1920x1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.get('enterwebsite.ext')
#do other stuff

Upvotes: 2

jsfehler
jsfehler

Reputation: 154

driver = webdriver.Chrome(driver2, options=options)

You're sending a WebDriver object as a positional argument.

https://www.selenium.dev/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#module-selenium.webdriver.chrome.webdriver

The first argument to WebDriver is the executable path.

Upvotes: 0

Related Questions