Wednesday, March 25, 2015

RUBY:: Form submit by webdriver

Use of selenium webdriver

require 'rubygems'
require 'selenium-webdriver'
require 'json'

For remote access
caps = Selenium::WebDriver::Remote::Capabilities.chrome
driver = Selenium::WebDriver.for(:remote, :url => "server_url", :desired_capabilities => caps)

For local access
driver = Selenium::WebDriver.for :firefox


driver.navigate.to "http://www.facebook.com/"
driver.find_element(:id, 'email').send_keys "aemailcom"
driver.find_element(:id, 'pass').send_keys "apssword"
driver.find_element(:xpath, "//input[@value='Log In']").click
puts driver.title
driver.quit

Use of watir webdriver

require 'rubygems'
require 'watir-webdriver'

driver = Watir::Browser.new :firefox
driver.navigate.to "http://www.facebook.com/"
driver.find_element(:id, 'email').send_keys "aemailcom"
driver.find_element(:id, 'pass').send_keys "apssword"
driver.find_element(:xpath, "//input[@value='Log In']").click
puts driver.url
driver.close

No comments:

Post a Comment