Chrome driver for Selenium in Mac

Selenium (E2E testing tool) uses ChromeDriver (exe that implements a WebDriver interface) to control Chrome.

Selenium expects chromedriver to be available in the path (eg. /usr/local/bin). It expects the Chrome browser to be available in (/Applications). The version of chromedriver and Chrome browser should match.

There are many methods to install chromedriver and Chrome. But here is one that I learnt today.

Assume that Chrome is in version 128, we want to install chromedriver v128. It can be done using puppeteer!

npx @puppeteer/browsers install chromedriver@128

It installs the Chrome driver in the current directory. Search the downloaded folder for chromedriver (pick the executable file, not the folder).

sudo mv chromedriver /usr/local/bin

You should be able to check the version of chromedriver using chromedriver —version

The mismatch happens when you do installation of selenium several months back and use a recent version of Chrome. Another way to resolve this problem is to delete node_modules and reinstall everything. In addition, there is a selenium cache at ~/.cache/selenium that can be removed to fix the problem.

Happy tinkering!

0
Subscribe to my newsletter

Read articles from Vijay Thirugnanam directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vijay Thirugnanam
Vijay Thirugnanam

Engineer working at Cerebras in Toronto. Apart from work, read books and tweet about meditation.