The Issue

Much like textboxes, radio buttons are a commonality when testing browsers. Used in similar circumstances as checkboxes, Radio buttons are most often utilized to make someone select only one option, instead of multiple. We’ll take a look at two basic radio button interactions utilize Ruby & Watir Webdriver/Selenium commands.

The Answer

These Watir Webdriver commands will select a radio button, and check if it is validated. Lets check these out in action.

The Code

We’ll be testing the radio buttons on the Watir Webdriver demo page.

The Result

We can save the file (testradio.rb) and run it from the command line, with the following result:

  • Browser opens
  • Browser navigates to the Watir Webdriver demo page
  • Checks radio button for “A gem
  • Returns the current status of the radio button

The Takeaway

Radio buttons are an important element to know how to deal with; using this pair of Ruby & Watir Webdriver/Selenium commands, you can start validating them on your website/app.