Playlist MyTV untuk smart TV berserta intisari rancangan bermula RM4.99 sebulan. Selanjutnya →

Install Selenium + NodeJS + geckodriver (Firefox) on MacOS

Sabtu, 11 November 2023, 4:45 pm0

Previously I used Selenium in NodeJS environment with Chrome , but because of Google updated Chrome regularly, its webdriver wasn’t updated quickly enough.

EED00FCF-78A5-4836-B05A-9694BD5A243C.jpeg
Firefox running in automated mode.

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.

Chrome webdriver (https://chromedriver.storage.googleapis.com/index.html) latest version as of November 2023:

  • webdriver = 114.0.5735.90
  • Chrome = 119.0.6045.123
  • major version must match (114 vs 119)

Pre-requisite:

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, add export PATH=$PATH:~/Documents/geckodriver
    • run source ~/.zshrc in terminal to update the environment variable values

Try run geckodriver, if it’s showing dialog similar like below, this one is when I try to run chromedriver:

5C0B6683-E4D1-46BA-BF4D-510102B73089.jpeg
Cannot be opened because the developer cannot be verified.

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

Komentar (0):

FB: https://www.facebook.com/100810608155424/posts/1010690183431227/

Tulis komen: