Selenium 4 add Binary path

Issue

Good morning, I use selenium to do some webscraping, until yesterday everything worked fine, now I get this error, I know it is due to updating the binary, but as I want to share the programm, I would like the binary to be in the folder I created, so that it works with whoever opens the programme.
This is the code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support.ui import WebDriverWait


# options
options = Options()
options.use_chromium = True
options.add_argument("--headless")
options.add_argument("disable-gpu")
options.add_argument('--allow-running-insecure-content')
options.add_argument('--ignore-certificate-errors')
options.add_experimental_option('excludeSwitches', ['enable-logging'])


# Selenium driver path
s=Service("./Monatseinteilung/driver/msedgedriver.exe")

driver = webdriver.Edge(service=s, options=options)

this is the error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of MSEdgeDriver only supports MSEdge version 100
Current browser version is 102.0.1245.30 with binary path C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

Solution

You have to change your msedgedriver.exe driver to match the MS Edge version you have installed on your computer (102). You can download that from here. Replace your msedgedriver.exe and this script should start working. You will have to do that every time MS Edge updates.

Since you are using Python and since you want to share the program, this may not be very convenient. So instead, you can try libraries such as selenium_driver_updater, or webdriver_auto_update although webdriver_auto_update only seems to support Chrome. After that, you can check for the latest driver available every time you run your script

For selenium_driver_updater

filename = DriverUpdater.install(path=base_dir, driver_name=DriverUpdater.chromedriver, upgrade=True, check_driver_is_up_to_date=True, old_return=False)
driver = webdriver.Chrome(filename)

For webdriver_auto_update:

check_driver('folder/path/of/your/chromedriver')

Answered By – M B

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published