anahorn

Selenium WebDriver Ruby: Part 3 (Forms) 2

Jun 4th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.68 KB | None | 0 0
  1. require 'rubygems'
  2. require 'selenium-webdriver'
  3.  
  4. browser = Selenium::WebDriver.for :firefox
  5. browser.get "http://localhost/page3"
  6.  
  7. wait = Selenium::WebDriver::Wait.new(:timeout => 15)
  8.  
  9. # Add text to a text box
  10. input = wait.until {
  11.     element = browser.find_element(:name, "searchbox")
  12.     element if element.displayed?
  13. }
  14. input.send_keys("Information")
  15.  
  16. # Check that the form exists
  17. form = wait.until {
  18.     element = browser.find_element(:name, "input")
  19.     element if element.displayed?
  20. }
  21. puts "Test Passed: Form input found" if form.displayed?
  22.  
  23. # Click the button based the form it is in (you can also call 'submit' method)
  24. form.find_element(:name, "submit").click
  25.  
  26. browser.quit
Advertisement
Add Comment
Please, Sign In to add comment