Ruby1.8.7 安装和使用selenium

引用
Selenium可以用来模拟浏览器页面点击,可以用来做页面功能测试,也可以用来做一些自动化脚本,它提供啦ruby版本实现,本文基于IE,当然它也支持其它主流浏览器


1. 安装selenium-webdriver
gem install selenium-webdriver


2. 安装Internet Explorer Driver Server,解压出来的EXE添加到path路径上面
http://code.google.com/p/selenium/downloads/detail?name=IEDriverServer_Win32_2.33.0.zip


3. 简单的测试脚本(程序流程:打开百度,输入关键字,搜索,然后后退到上一个页面)
require 'selenium-webdriver'
ie = Selenium::WebDriver.for :ie
ie.get 'www.baidu.com'
puts ie.current_url
inputElement=ie.find_element(:name, 'wd') 
# p inputElement.text
inputElement.send_keys "123"
inputElement=ie.find_element(:id, 'su').submit()
ie.navigate.back


如果遇到如下异常,对着IE按Ctrl+0
引用
Unexpected error launching Internet Explorer. Browser
zoom level was set to 125%. It should be set to 100% (Selenium::WebDriver::Error::NoSuchDriverError)


4. 更多Selenium api文档
http://docs.seleniumhq.org/docs/03_webdriver.jsp#selenium-webdriver-api-commands-and-operations

猜你喜欢

转载自caerun.iteye.com/blog/1891796