5

When running this code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdrivermanager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().download_and_install())
driver.get("http://www.python.org")

This results in the following exception at the line where the chromedriver is installed:

TypeError: expected str, bytes or os.PathLike object, not tuple

Note that I am aware that there already exist many threads about this topic but since the webdrivermanager seems to have been updated majorly the previous solutions do not work.

Also a quick side note: I installed webdrivermager via conda instead of pip. but that should not be of concern.

EDIT: Entire stack trace:

Traceback (most recent call last): File "C:\Users\stefa\OneDrive - Johannes Kepler Universität Linz\Dokumente\GitHub\briefly\src\crawler\crawler.py", line 19, in driver = webdriver.Chrome(ChromeDriverManager().download_and_install()) File "C:\Users\stefa\anaconda3\envs\briefly\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\stefa\anaconda3\envs\briefly\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Users\stefa\anaconda3\envs\briefly\lib\subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\stefa\anaconda3\envs\briefly\lib\subprocess.py", line 1360, in _execute_child args = list2cmdline(args) File "C:\Users\stefa\anaconda3\envs\briefly\lib\subprocess.py", line 565, in list2cmdline for arg in map(os.fsdecode, seq): File "C:\Users\stefa\anaconda3\envs\briefly\lib\os.py", line 822, in fsdecode filename = fspath(filename) # Does type-checking of filename. TypeError: expected str, bytes or os.PathLike object, not tuple

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Stefan
  • 1,122
  • 3
  • 14
  • 38

3 Answers3

4

There are two issues in your code block as follows:

  • You need to import ChromeDriverManager from webdriver_manager.chrome
  • As per Webdriver Manager for Python download_and_install() isn't supported and you have to use install()

So your effective code block will be:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://www.python.org")

On system the console output will be:

C:\Users\Admin\Desktop\Python Programs>python webdriver-manager_ChromeDriverManager.py
[WDM] -

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 95.0.4638
[WDM] - Get LATEST driver version for 95.0.4638
[WDM] - There is no [win32] chromedriver for browser 95.0.4638 in cache
[WDM] - Get LATEST driver version for 95.0.4638
[WDM] - Trying to download new driver from https://chromedriver.storage.googleapis.com/95.0.4638.54/chromedriver_win32.zip
[WDM] - Driver has been saved in cache [C:\Users\Admin\.wdm\drivers\chromedriver\win32\95.0.4638.54]

DevTools listening on ws://127.0.0.1:50921/devtools/browser/c26df2aa-67aa-4264-b1dc-34d6148b9174

You can find a relevant detailed discussion in ModuleNotFoundError: No module named 'webdriver_manager' error even after installing webdrivermanager

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Did you try this with conda or pip? Conda cannot install webdriver-manager but only webdrivermanager and this package only contains the download_an_install function instead of the usual install function – Stefan Oct 29 '21 at 20:24
  • Check the linked [discussion](https://stackoverflow.com/questions/63421086/modulenotfounderror-no-module-named-webdriver-manager-error-even-after-instal). It shouldn't matter whether you install through pip/conda. But `pip install webdriver_manager` followed by `from webdriver_manager.chrome import ChromeDriverManager` – undetected Selenium Oct 29 '21 at 20:28
3

Here my solution:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
s = Service('chromedriver/chromedriver96.exe')
driver = webdriver.Chrome(service=s, options=options)
jarh1992
  • 603
  • 7
  • 8
3
  1. Install Webdriver Manager for Python: pip install webdriver-manager
  2. Import ChromeDriverManager: from webdriver_manager.chrome import ChromeDriverManager
  3. Use webdriver: service = ChromeService(executable_path=ChromeDriverManager().install()) driver = webdriver.Chrome(service=service)
Eduard
  • 31
  • 2