anahorn

Selenium WebDriver Ruby: Part 6 (Radio Buttons) 2

Jun 4th, 2019
143
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/page6"
  6.  
  7. wait = Selenium::WebDriver::Wait.new(:timeout => 15)
  8.  
  9. # Check that the radio button exists
  10. puts "Test Passed: Radio button found" if wait.until {
  11.     browser.find_element(:name, "radiobutton1").displayed?
  12. }
  13.  
  14. # Change the state of the Radio Buttons
  15. cb1 = wait.until {
  16.     element = browser.find_element(:name, "radiobutton1")
  17.     element if element.displayed?
  18. }
  19. cb1.click if cb1.selected? == false
  20.  
  21. cb3 = wait.until {
  22.     element = browser.find_element(:name, "radiobutton3")
  23.     element if element.displayed?
  24. }
  25. cb3.click if cb3.selected? == false
  26.  
  27. browser.quit
Advertisement
Add Comment
Please, Sign In to add comment