1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL環境のRubyにて、selenium(Firefox)を利用する

Last updated at Posted at 2021-01-14

WSL環境のRubyにて、selenium(Firefox)を利用する

事前準備

必要なライブラリのインストール

firefoxをインストール

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

firefoxのバージョンを確認

firefox --version

geckodriverをインストール

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

動作確認

  • パッケージの変更
Gemfile
source "https://rubygems.org"

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

gem "webdriver"
gem "selenium-webdriver"
  • パッケージの反映
bundle install
  • Rubyのサンプルコード
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
  • 動作確認
ruby test.rb

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?