[Linux: Ruby] Use the driver with selenium without specifying the browser driver path

environment

Ubuntu 18.04 LTS Ruby 2.6.5 selenium-webdriver 3.142.7

Introduction

When using selenium-webdriver with ruby, if you put the driver file in the directory where the path is in linux, you can use the driver without specifying the driver path. I will summarize the method with notes at that time.

Put the driver in a directory that is in your path

This time, I will use the Chrome driver as an example. From the following, proceed assuming that the driver is installed.

First, look at the environment variables to see which directories are in your path.

$ printenv PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

The directories that are in the path are displayed, separated by ":". This time I put the driver file in "usr / local / bin".

/usr/local/bin$ ls
chromedriver

If you call the chrome driver with selenium in this state, you can use it without specifying the path.

test.rb


require 'selenium-webdriver'

d = Selenium::WebDriver.for :chrome
d.get('http://****')

The driver file name is not recognized unless it is "chrome driver"

If the driver file name is not "chromedriver", an error will occur at runtime. I installed the driver for ver.83, so I saved it as "chromedriver83" when installing the driver, but I stumbled upon an error.

/usr/local/bin$ ls
chromedriver83

Error when running script

 Unable to find chromedriver. Please download the server from (Selenium::WebDriver::Error::WebDriverError)

I'm told I can't find the chrome driver

If you specify the path, you can use another file name.

If you want to specify the driver path in the script, you can use a different file name.

test.rb


require 'selenium-webdriver'

Selenium::WebDriver::Chrome::Service.driver_path = '/usr/local/bin/chromedriver83'
d = Selenium::WebDriver.for :chrome
d.get('http://****')

By the way, with this method, it doesn't matter if the path is passed or not.

Recommended Posts

[Linux: Ruby] Use the driver with selenium without specifying the browser driver path
Use thymeleaf3 with parent without specifying spring-boot-starter-parent in Spring Boot
The difference between programming with Ruby classes and programming without it
Update to the latest version without specifying the version with gradle wrapper
About specifying the JAXRS path
Can Selenium automate the browser?
Use Ruby with Google Colab
Ruby Scraping-Move Selenium Headless with VPS.
Let's use Amazon Textract with Ruby
Programming with ruby (on the way)
Follow the link with Selenium (Java)