Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to obtain chromedriver.exe using Selenium Manager

Error: Message: Unable to obtain chromedriver.exe using Selenium Manager; Message: Unsuccessful command executed: /var/task/selenium/webdriver/common/linux/selenium-manager --browser chrome --output json; Expecting value: line 1 column 1 (char 0)

Code:

from http.server import BaseHTTPRequestHandler
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

class Handler(BaseHTTPRequestHandler):
   
   def do_GET(self):
       self.send_response(200)
       self.send_header('Content-type', 'text/plain')
       self.end_headers()

       try:
           service = Service(executable_path=r'./chromedriver.exe')
           options = webdriver.ChromeOptions()
           options.add_argument('--headless')
           driver = webdriver.Chrome(service=service, options=options)
           driver.get('https://www.example.com/')
           driver.save_screenshot("screenshot_example.png")
           
       except Exception as e:
           # Print the exception error
           self.wfile.write(f'{str(e)}'.encode('utf-8'))

       self.wfile.write('Hello, world!'.encode('utf-8'))
       return

I tried changing ./chromedriver.exe in many different ways already with/without .exe and / or the ./

like image 250
Jojo Momo Avatar asked Aug 30 '25 17:08

Jojo Momo


1 Answers

I've same issue while updating my previous code, and here is my solution:

Find the chromedriver path. In my case, run dpkg -L chromium-chromedriver and get /usr/bin/chromedriver.

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

# Add service
service = Service(executable_path="/usr/bin/chromedriver")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)

Test environment:

  • OS: Raspberry Pi OS 64-bit
  • Python: 3.9
  • selenium: 4.12.0
  • chromedriver: 113.0.5672.95
like image 88
cocobird Avatar answered Sep 02 '25 07:09

cocobird