© Courtney Zhan, Edited by Zhimin Zhan 2024
Z. Zhan (ed.)Selenium WebDriver Recipes in C#https://doi.org/10.1007/979-8-8688-0023-8_6

6. Radio Button

Courtney Zhan1  
(1)
Fitzgibbon, QLD, Australia
 
Figure 6-1 shows the typical radio button we’re all familiar with.

A radio button selects options from male and female. Male is selected.

Figure 6-1

Typical radio button

HTML source:
<input type="radio" name="gender" value="male" id="radio_male" checked="true">Male<br/>
<input type="radio" name="gender" value="female" id="radio_female">Female

Select a Radio Button

driver.FindElement(By.XPath("//input[@name='gender' and @value='female']")).Click();
System.Threading.Thread.Sleep(500); ...

Get Selenium WebDriver Recipes in C#: Practical Testing Solutions for Selenium WebDriver 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.