Install Selenium + NodeJS + geckodriver (Firefox) on MacOS
Sabtu, 11 November 2023, 4:45 pm48
Previously I used Selenium in NodeJS environment with Chrome #browser, but because of Google updated Chrome regularly, its webdriver wasn’t updated quickly enough.
I couldn’t figure out how to disable Chrome auto update, and an outdated webdriver doesn’t work with new version of Chrome. So I decided to switch to using Firefox and its webdriver, named geckodriver.
- webdriver = 114.0.5735.90
- Chrome = 119.0.6045.123
- major version must match (114 vs 119)
- Firefox browser – https://www.mozilla.org/firefox/download/thanks/
- NodeJS & npm –
brew install node
- Download compiled binary from https://github.com/mozilla/geckodriver/releases/, latest version as of November 2023 – geckodriver-v0.33.0-macos.tar.gz
- Untar it & move
- Or, can put it in any folder & add that folder to $PATH environment variable:
- I put it in
source ~/.zshrcin terminal to update the environment variable values
- I put it in
geckodriver, if it’s showing dialog similar like below, this one is when I try to run
To solve this, go to System Preferences > Security & Privacy > Allow apps downloaded from, click Allow Anyway.
Create NodeJS app & using selenium-webdriver node module:
mkdir myapp cd myapp npm init -y npm install selenium-webdriver
To test the installation, create
myapp folder, and copy the source code from this gist:
- open one tab in Terminal, and run
- In another tab, run test.js: