Ruby
firefox
Selenium

Selenium のサンプル (Ruby)

Selenium のサンプルです。

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

sudo gem install selenium-webdriver

サンプルプログラム

example01.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
#
#   example01.rb
#
#                   Mar/28/2018
#
# ------------------------------------------------------------------
require 'selenium-webdriver'
# ------------------------------------------------------------------
STDERR.puts "*** 開始 ***"

url = 'http://example.selenium.jp/reserveApp/'

driver = Selenium::WebDriver.for :firefox
driver.get(url)

#
driver.find_element(:id,'reserve_month').clear()
driver.find_element(:id,'reserve_month').send_keys("4")
driver.find_element(:id,'reserve_day').clear()
driver.find_element(:id,'reserve_day').send_keys("10")
driver.find_element(:id,'reserve_term').clear()
driver.find_element(:id,'reserve_term').send_keys("3")
driver.find_element(:id,'headcount').clear()
driver.find_element(:id,'headcount').send_keys("2")
#
str_select = "input[type='radio'][name='bf'][value='off']"
item=driver.find_elements(:css,str_select)[0]
item.click()
#
str_select = "input[type='checkbox'][id='plan_b']"
item=driver.find_elements(:css,str_select)[0]
item.click()
#
driver.find_element(:id,'guestname').clear()
driver.find_element(:id,'guestname').send_keys("明智小五郎")
#
driver.find_element(:id,'goto_next').click()
#
STDERR.puts "*** 終了 ***"
#
# ------------------------------------------------------------------

実行方法

./example01.rb