LoginSignup
0
0

More than 1 year has passed since last update.

Mac + Ruby + selenium を初めて使う

Posted at

準備

gemのインストール

gem install selenium-webdriver

chromeドライバのインストール

brew install chromedriver

コード例

require 'selenium-webdriver'

session = Selenium::WebDriver.for :chrome

session.navigate.to "https://example.com"

if session.save_screenshot('./example-com.png')
  puts "Screen shot saved"
end

session.quit

Macでの許可

rubyを実行すると以下ダイアログが表示されるのでキャンセルする。

image

Macの設定で許可する。「このまま許可」を選ぶ。

image

もう一度Rubyを実行して「開く」を選ぶ。

image

結果

実行するとブラウザが起動してスクリーンショット画像が生成される。

image

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
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
0
0