Home > Mobile >  Selenium ChromeDriver issue using Webdriver Manager for Python
Selenium ChromeDriver issue using Webdriver Manager for Python

Time:10-30

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

CodePudding user response:

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

  • Related