Automating radio buttons and radio groups

Selenium WebDriver supports Radio Button and Radio Group controls using the WebElement class. We can select and deselect the radio buttons using the click() method of the WebElement class and check whether a radio button is selected or deselected using the isSelected() method.

In this recipe, we will see how to work with the Radio Button and Radio Group controls.

How to do it...

Let's create a test which gets Radio Button and Radio Group controls. We will perform select and deselect operations.

@Test public void testRadioButton() { //Get the Radiobutton as WebElement using it's value attribute WebElement petrol = driver.findElement(By.xpath("//input[@value='Petrol']")); //Check if its already selected? otherwise ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.