Reputation: 1372
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
Upvotes: 7
Views: 62212
Reputation: 67
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
Upvotes: 2
Reputation: 31
Upvotes: 3
Reputation: 644
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)
Upvotes: 3
Reputation: 193298
There are two issues in your code block as follows:
webdriver_manager.chrome
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 windows-10 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
Upvotes: 6