Selenium ChromeDriver issue using Webdriver Manager for Python
I

4

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

Intradermal answered 29/10, 2021 at 19:45 Comment(0)
M
5

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

Metatherian answered 29/10, 2021 at 20:14 Comment(2)
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 functionIntradermal
Check the linked discussion. It shouldn't matter whether you install through pip/conda. But pip install webdriver_manager followed by from webdriver_manager.chrome import ChromeDriverManagerMetatherian
P
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)
Pinchpenny answered 24/12, 2021 at 15:17 Comment(0)
T
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)
Torpedoman answered 4/4, 2022 at 8:0 Comment(1)
where ChromeService come from anything in python must imported firstGilbart
S
0

Adding this in case others stumble onto this. This uses a combination of selenium version 4+'s Service class and sets the executable_path to ChromeDriverManager().install() and it worked for me. This beats having to constantly update via homebrew.

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


        web_driver = webdriver.Chrome(
            service=Service(executable_path=ChromeDriverManager().install()),
            options=opts
        )

Console output

/Users/ekim/opt/anaconda3/envs/bots/bin/python -m src.app.__main__ 
2024-02-21 12:13:14,064 - INFO - Initializing ChromeDriver...
2024-02-21 12:13:14,064 - INFO - ====== WebDriver manager ======
2024-02-21 12:13:14,380 - INFO - Get LATEST chromedriver version for google-chrome
2024-02-21 12:13:14,384 - INFO - Get LATEST chromedriver version for google-chrome
2024-02-21 12:13:14,384 - INFO - There is no [mac64] chromedriver "122.0.6261.57" for browser google-chrome "122.0.6261.57" in cache
2024-02-21 12:13:14,395 - INFO - Get LATEST chromedriver version for google-chrome
2024-02-21 12:13:14,609 - INFO - WebDriver version 122.0.6261.57 selected
2024-02-21 12:13:14,610 - INFO - Modern chrome version https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.57/mac-x64/chromedriver-mac-x64.zip
2024-02-21 12:13:14,610 - INFO - About to download new driver from https://storage.googleapis.com/chrome-for-testing-public/122.0.6261.57/mac-x64/chromedriver-mac-x64.zip
2024-02-21 12:13:14,836 - INFO - Driver downloading response is 200
2024-02-21 12:13:15,305 - INFO - Get LATEST chromedriver version for google-chrome
2024-02-21 12:13:15,430 - INFO - Driver has been saved in cache [/Users/ekim/.wdm/drivers/chromedriver/mac64/122.0.6261.57]

Process finished with exit code 0
Spinule answered 21/2 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.