anahorn

Selenium WebDriver Ruby: Part 5 (Checkboxes) 2

Jun 4th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.74 KB | None | 0 0
  1. require 'rubygems'
  2. require 'selenium-webdriver'
  3.  
  4. browser = Selenium::WebDriver.for :firefox
  5. browser.get "http://localhost/page5"
  6.  
  7. wait = Selenium::WebDriver::Wait.new(:timeout => 15)
  8.  
  9. cb = browser.find_element(:name, "checkthebox")
  10.  
  11. # Check that the checkbox exists
  12. cb = wait.until {
  13.     element = browser.find_element(:name, "checkthebox")
  14.     element if element.displayed?
  15. }
  16. puts "Test Passed: The check box exists" if cb
  17.  
  18. # Check the checkbox
  19. cb.click
  20.  
  21. # Verify the state of checkbox
  22. puts "Test Passed: The check box is selected now" if cb.selected? == true
  23.  
  24. sleep 2
  25.  
  26. # Un-Check the checkbox
  27. cb.click
  28.  
  29. # Verify the state of checkbox again
  30. puts "Test Passed: The check box is unselected now" if cb.selected? == false
  31.  
  32. browser.quit
Advertisement
Add Comment
Please, Sign In to add comment