tags

[1]

Rubyのwatirでブラウザを操作する

watir/watir: Watir Powered By Selenium

● watirのインストール

gem install watir
gem install watir-webdriver

● watirのでGoogleにログインする

require "rubygems"
require "watir"

email         = "xxx@yyy.zzz"
password = "ppppppppp"

browser = Watir::Browser.new :chrome
browser.goto("https://accounts.google.com/servicelogin?hl=ja#identifier")

element = browser.text_field(:name, "Email")
element.flash
element.value = email

element = browser.button(css:"#next")
element.flash
element.click

browser.div(css:"#signIn").wait_while_present

element = browser.text_field(:name, "Passwd")
element.flash
element.value = password

element = browser.button(css:"#signIn")
element.flash
element.click

browser.wait # ブラウザの読込完了まで待機
puts browser.url

● Watir Webdriver Cheatsheet

http://bit.ly/2i0ypke

● Watir firefox add-on

https://addons.mozilla.org/ja/firefox/tag/watir

● 参考

http://alpha-netzilla.blogspot.jp/2014/09/selenium.html http://momota.github.io/blog/2016/05/28/selenium-know-how/

No.1076
04/14 09:43

edit

Selenium