Use selenium (Firefox) in Ruby in WSL environment

Use selenium (Firefox) in Ruby in WSL environment

Advance preparation

Installation of required libraries

install firefox

sudo apt-get update
sudo apt-get install -y firefox

Check the version of firefox

firefox --version

Install gecko driver

https://github.com/mozilla/geckodriver/releases

wget https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz
tar zxvf geckodriver-v0.28.0-linux64.tar.gz
chmod +x geckodriver
sudo mv -f geckodriver /usr/local/share/geckodriver
sudo ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver
sudo ln -s /usr/local/share/geckodriver /usr/bin/geckodriver

Operation check

--Package change

Gemfile


source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "webdriver"
gem "selenium-webdriver"

--Package reflection

bundle install

--Ruby sample code

test.rb


require "selenium-webdriver"

opts = Selenium::WebDriver::Firefox::Options.new(args: ['--headless'])
driver = Selenium::WebDriver.for(:firefox, options: opts)

driver.navigate.to "https://google.com/"

puts driver.title

driver.quit

--Operation check

ruby test.rb

reference

--How to test Ruby with Selenium WebDriver [For beginners] https://techacademy.jp/magazine/18704

--Run Headless chrome on Ruby and Selenium on Ubuntu/Linux https://qiita.com/meguroman/items/41ca17e7dc66d6c88c07

-[Complete version] Cheat sheet that automatically operates (crawling / scraping) the browser with Python and Selenium https://tanuhack.com/selenium/

Recommended Posts

Use selenium (Firefox) in Ruby in WSL environment
Use selenium (Chrome) in Ruby in WSL environment
Install ruby serial port in WSL environment
Update Ruby in Unicorn environment
Use ruby variables in javascript.
WSL2 + Ubuntu 20.04 Install Vivado in LTS environment
Use docker in proxy environment on ubuntu 20.04.1
How to use environment variables in RubyOnRails
I want to use arrow notation in Ruby
Class in Ruby
Heavy in Ruby! ??
[Rails] How to use PostgreSQL in Vagrant environment
Use Shift Right and Shift Left properly in Selenium
[Ruby] How to use standard output in conditional branching
People who don't usually use Ruby build a Ruby environment
Install Rust in WSL2 Ubuntu environment and build WASM build environment
Beginners use ubuntu in windows to prepare rails environment
Use Coveralls with GitHub Actions in a Ruby repository
Handling of date and time in Ruby. Use Date and Time properly.
About eval in Ruby
Use java.time in Jackson
Use Interceptor in Spring
Use OpenCV in Java
Use MouseListener in Processing
Use images in Rails
Output triangle in Ruby
Use PostgreSQL in Scala
Variable type in ruby
Use PreparedStatement in Java
Fast popcount in Ruby
About docker.credentials.errors.StoreErrorTraceback in wsl2
Install / run a standalone robot simulator in wsl2 / docker environment!
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Use docker-compose.yml which is different for each environment in Makefile