Webdriver_Ruby实例代码(1)

require 'watir-webdriver'
b = Watir::Browser.new
b.goto 'bit.ly/watir-webdriver-demo'
b.text_field(:id => 'entry_0').set 'your name'
b.select_list(:id => 'entry_1').select 'Ruby'
b.select_list(:id => 'entry_1').selected? 'Ruby'
b.div(:class => 'ss-form-entry').button.click
b.text.include? 'Thank you'
#webdriver通用watir语法
browser.goto('http://myserver/mypage')
# to enter text into a text field - assuming the field is named 'username'
browser.text_field(:name, 'username').set('Paul')
# if there was a text field that had an id of 'company_ID', you could set it to 'Ruby Co':
browser.text_field(:id ,'company_ID').set('Ruby Co')
# to click a button that has a caption of 'Cancel'

ie.button(:value, 'Cancel').click

///////////////////////////////////////////////////////////////////////////////////

require 'watir-webdriver'
browser = Watir::Browser.new :firefox
browser.goto "http://google.com"
browser.text_field(:name => 'q').set("WebDriver rocks!")
browser.button(:name => 'btnG').click
puts browser.url
browser.close

//////////////////////////////////////////////////////////////////////////////////////////////////////

require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
b.select_list( :id => 'entry_1' ).wait_until_present
b.text_field( :id => 'entry_0' ).when_present.set 'your name'
b.button( :value => 'Submit' ).click
b.button( :value => 'Submit' ).wait_while_present
Watir::Wait. until { b.text.include? 'Thank you' }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

require 'watir-webdriver'
b = Watir::Browser. new
b.driver.manage.timeouts.implicit_wait = 3 #3 seconds
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#!/usr/bin/env ruby   
require 'rubygems'  
require 'selenium-webdriver'   
caps = Selenium::WebDriver::Remote::Capabilities.firefox  
caps.version = "8"  
caps.platform = :WINDOWS  
driver = Selenium::WebDriver.for(  
  :remote,  
  :url => "http://API_KEY:[email protected]:4444/wd/hub",  
  :desired_capabilities => caps)  
driver.navigate.to "http://www.google.com"  
element = driver.find_element(:name, 'q')  
element.send_keys "Hello WebDriver!"  
element.submit  
puts driver.title  
driver.quit 


你可能感兴趣的:(Webdriver_Ruby实例代码(1))