0

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 ./

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Jojo Momo
  • 21
  • 1
  • 9

2 Answers2

0

You don't need to pass the key executable_path along with absolute path of the ChromeDriver. You just need to pass the absolute path of the ChromeDriver as follows:

service = Service('./chromedriver.exe')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(service=service, options=options)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

It looks like you're trying to use chromedriver.exe on a Linux machine, but that is a Windows file extension. On Mac / Linux, the file is just chromedriver.

As of selenium 4.10.0, (where the driver manager is now included and out of beta), you can just do this:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
# ...
driver.quit()
Michael Mintz
  • 9,007
  • 6
  • 31
  • 48