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 ./
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With