Forums

Chrome and Chromedriver use different versions

I'm trying to get a task using selenium to webscrape and I'm getting an error that says :

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 117 Current browser version is 90.0.4430.212 with binary path /usr/bin/chromium

my code is

chrome_options = webdriver.ChromeOptions()
service = webdriver.ChromeService()
chrome_options.add_argument("--no-sandbox")
chrome_options.headless = True
chrome_options.add_argument("--disable-gpu")
browser  = webdriver.Chrome(service=service, options=chrome_options)

I'm folllowing the CI/CD tutorial so my code in in /var/www/sites/mysite. How do I get selenium to use the correct chromedriver?

Do not use a chromedriver that you brought to PythonAnywhere. If you do not specify a chromedriver, then selenium will use the default one that is already installed and works

I haven't imported another version of chromedriver. Interestingly, if I remove the line

service = webdriver.ChromeService()

then I get the opposite issue happening; the version of chromedriver and Chrome get swapped.

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 90 Current browser version is 117.0.5938.88 with binary path /home/citizenpain/.cache/selenium/chrome/linux64/117.0.5938.88/chrome

What do you see when you run "which chromedriver" in your console?

When I type "which chromedriver", I get

/usr/local/bin/chromedriver

my current hack that makes it work on both my machine and pythonanywhere is

chrome_options = webdriver.ChromeOptions()
is_development = os.getenv("DJANGO_DEVELOPMENT", False)
service_kwargs = {}
if not is_development:
   service_kwargs["executable_path"] = "/usr/local/bin/chromedriver"
service = webdriver.ChromeService(**service_kwargs)
chrome_options.add_argument("--no-sandbox")
chrome_options.headless = True
chrome_options.add_argument("--disable-gpu")
browser  = webdriver.Chrome(service=service, options=chrome_options)

Still don't know why the original thing isn't working, but this seems fine for right now.

Thanks for letting us know.