This is a card in Dave's Virtual Box of Cards.

Selenium WebDriver with Ruby

Created: 2022-03-17

First, had to get a newer version of Ruby on the machine.

$ sudo gem install selenium-webdriver
Fetching rubyzip-2.3.2.gem
Fetching selenium-webdriver-4.1.0.gem
...

Then gotta get the driver binary. I’m a Firefox guy, but this particular task requires Chrome.

$ ruby hello.rb
  /home/dave/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/selenium-webdriver-4.1.0/
  lib/selenium/webdriver/common/service.rb:104:in `binary_path': Unable to find
  chromedriver. Please download the server from (Selenium::WebDriver::Error::WebDriverError)
  https://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH.
  More info at https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
  ...


$ google-chrome-stable --version
  Google Chrome 99.0.4844.74
$ wget https://chromedriver.storage.googleapis.com/99.0.4844.51/chromedriver_linux64.zip
$ unzip chromedriver_linux64.zip
  Archive:  chromedriver_linux64.zip
    inflating: chromedriver
$ sudo ln -s /home/dave/work/selen/chromedriver /usr/local/bin/chromedriver
$ chromedriver --version
  ChromeDriver 99.0.4844.51 (d537ec02474b5afe23684e7963d538896c63ac77-refs/branch-heads/4844@{#875})

Now the hello.rb test works. Here’s the source:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome
driver.get 'https://selenium.dev'
driver.quit

Sure enough, it opens up a copy of Chrome, briefly visits the selenium website, and exits.

ruby-selenium-proxy