本blog是以ruby语言为基础的,ruby的安装很简单,可以下载ruby安装文件自行安装,个人喜欢用railsinstaller-2.0.0.exe进行安装,它会安装ROR框架和git。
SE2.0的安装
命令行中运行:
gem install selenium-webdriver
如果不想要ri和rdoc
gem install selenium-webdriver --no-ri --no-rdoc
Successfully installed json_pure-1.6.1
Successfully installed rubyzip-0.9.4
Successfully installed ffi-1.0.11-x86-mingw32
Successfully installed childprocess-0.2.2
Successfully installed selenium-webdriver-2.12.2
5 gems installed
安装成功。
开始第一个脚本
require 'rubygems'
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get "http://google.com"
element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit
puts "Page title is #{driver.title}"
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.title.downcase.start_with? "cheese!" }
puts "Page title is #{driver.title}"
driver.quit
如果你在运行时报
LoadError: no such file to load -- ffi_c
的错误,卸载ffi,重新安装ffi 1.0.9版本的
卸载:gem unistall ffi
安装:gem install ffi -v 1.0.9