Unable to obtain chromedriver using Selenium Manager; Message: Unable to obtain working Selenium Manager binary

3,354 views
Skip to first unread message

Caleb Page

unread,
Jul 26, 2023, 3:02:13 AM7/26/23
to ChromeDriver Users
Hello, everyone. I just found this group, and I'm hoping that someone may be able to point me in the right direction. I have a customer meeting tomorrow to show a tool I build for him, and it stopped working today when my Chrome updated to v115. 

This is my attempt to solve the problem (half of this is comments as I've been beating my head into the wall for half the night):

import os
import platform
import getpass
import json
import requests
import zipfile
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# This code gets the .json text from the URL. The requests.get() function makes a GET request to the URL and returns
# a Response object. The .text property of the Response object contains the body of the HTTP response, which in this
# case is the .json text.
url_json = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json'
response = requests.get(url_json)
json_text = response.text

# This code loads the JSON data into a Python object. The json.load() function takes a file object as input and
# returns a Python object that represents the JSON data.
data_dict = json.loads(json_text) # Convert the JSON data to a Python dictionary

# Get the operating system
os_name = platform.system()

# Determine the appropriate platform string based on the system
platform_string = None
if os_name == "Windows":
    platform_string = "win64"
elif os_name == "Linux":
    platform_string = "linux64"
elif os_name == "macOS":
    platform_string = "mac-x64"

# Find the URL of the chromedriver zip file for the correct platform
url_chrome = None
for download in data_dict['channels']['Stable']['downloads']['chromedriver']:
    if download['platform'] == platform_string:
        url_chrome = download['url']
        break
   
if url_chrome is None:
    print(f"Unable to find ChromeDriver download for platform {platform_string}")
    exit(1)
   
# Get the URL of the chromedriver zip file
# This example gets the URL for the Stable version on win64
#url_chrome = data_dict['channels']['Stable']['downloads']['chromedriver'][os_name_int]['url']

# Local path where the downloaded zip file will be saved
pathUsername = os.getlogin()

zip_dir = os.path.normpath(os.path.join("C:", os.path.sep, "Users", pathUsername, "chromedriver"))
os.makedirs(zip_dir, exist_ok=True) # Create directory if it does not exist

zip_path = os.path.join(zip_dir, "chromedriver.zip")

# Download the file
response = requests.get(url_chrome)
with open(zip_path, 'wb') as file:
    file.write(response.content)

# Path to extract the chromedriver to
extract_path = os.path.normpath(os.path.join("C:", os.path.sep, "Users", pathUsername, "chromedriver"))

# Extract the zip file
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
    zip_ref.extractall(extract_path)

# The os.name function returns a string, so it cannot be used as an index into the data_dict['channels']...
# ...['Stable']['downloads']['chrome'] list.
# To fix the error, you need to convert the os.name string to the appropriate integer.
if platform_string=="win64":
    os_name_int=4
if platform_string=="linux64":
    os_name_int=2
if platform_string=="mac-x64":
    os_name_int=10

url_chrome = data_dict['channels']['Stable']['downloads']['chromedriver'][os_name_int]['url']

# Extract the filename from the URL
filename = os.path.basename(url_chrome)  # e.g., "chromedriver-win64.zip"

# The unzipped filename would then be the filename without the .zip extension
unzipped_filename = os.path.splitext(filename)[0]  # e.g., "chromedriver-win64"

# Define Chromedriver filenames for each OS
chromedriver_filenames = {
    "Windows": "chromedriver.exe",
    "Linux": "chromedriver",
    "macOS": "chromedriver"
}

# Get the appropriate Chromedriver filename for the current OS
chromedriver_filename = chromedriver_filenames[os_name]

# Full path to the chromedriver executable
chromedriver_path = os.path.join(extract_path, chromedriver_filename)

# Create options object
#chrome_options = Options()

# Create service object using the path to the driver executable
#s = Service(chromedriver_path)

# Create new WebDriver instance with the path to the driver executable and options
driver = webdriver.Chrome(chromedriver_path)



It might start getting messy towards the end, here, as my efforts continued to fail. 

This is the error I receive:
# Create new WebDriver instance with the path to the driver executable and options
driver = webdriver.Chrome(chromedriver_path)
Traceback (most recent call last):

  File "C:\Users\u0505182\AppData\Local\anaconda3\envs\Pandas_Soup_Selenium_OpenPYXL\lib\site-packages\selenium\webdriver\common\driver_finder.py", line 42, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path

  File "C:\Users\u0505182\AppData\Local\anaconda3\envs\Pandas_Soup_Selenium_OpenPYXL\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 74, in driver_location
    browser = options.capabilities["browserName"]

AttributeError: 'str' object has no attribute 'capabilities'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Users\u0505182\AppData\Local\Temp\ipykernel_13336\4204605081.py", line 107, in <module>
    driver = webdriver.Chrome(chromedriver_path)

  File "C:\Users\u0505182\AppData\Local\anaconda3\envs\Pandas_Soup_Selenium_OpenPYXL\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 47, in __init__
    self.service.path = DriverFinder.get_path(self.service, self.options)

  File "C:\Users\u0505182\AppData\Local\anaconda3\envs\Pandas_Soup_Selenium_OpenPYXL\lib\site-packages\selenium\webdriver\common\driver_finder.py", line 44, in get_path
    raise NoSuchDriverException(f"Unable to obtain {service.path} using Selenium Manager; {err}")

NoSuchDriverException: Unable to obtain chromedriver using Selenium Manager; 'str' object has no attribute 'capabilities'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

Juan Arighini

unread,
Aug 29, 2023, 12:18:33 AM8/29/23
to ChromeDriver Users
Instala la version 4.8.3, funciona correctamente. pip install selenium==4.8.3

syntaxdev1 poncho

unread,
Sep 2, 2023, 7:25:14 PM9/2/23
to ChromeDriver Users
me salvaste
Reply all
Reply to author
Forward
0 new messages