Install Selenium + NodeJS + geckodriver (Firefox) on MacOS
Sabtu, 11 November 2023, 4:45 pm0
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)
Pre-requisite:
- Firefox browser – https://www.mozilla.org/firefox/download/thanks/
- NodeJS & npm –
brew install node
Install geckodriver:
- 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
geckodriver
to/usr/local/bin/
- Or, can put it in any folder & add that folder to $PATH environment variable:
- I put it in
~/Documents/geckodriver/
folder - Edit
~/.zshrc
, addexport PATH=$PATH:~/Documents/geckodriver
- run
source ~/.zshrc
in terminal to update the environment variable values
- I put it in
Try run geckodriver
, if it’s showing dialog similar like below, this one is when I try to run chromedriver
:
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 test.js
insider myapp
folder, and copy the source code from this gist:
- open one tab in Terminal, and run
geckodriver
- In another tab, run test.js:
node test.js
Masak roti canai kuah dhal kat rumah
12 November 2023