O'Reilly logo

Selenium Testing Tools Cookbook by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required