...

/

Working with Radio Buttons

Working with Radio Buttons

Learn how to find and interact with radio buttons using Selenium.

Select a radio button by ID

Most of the time, we can use the ID of the radio button to click it.

driver.findElement(By.id("radio_female")).click();

Select a radio button by name

Another less efficient way of selecting a radio button is to use its name:

driver.findElement(By.xpath("//input[@name='gender' and @value='female']")).click();
driver.sleep(200);
driver.findElement(By.xpath("//input[@n
...