Clicking a radio button with Selenium

Here is a little code to find and click the first radio button in a set using Selenium:


var didYouGraduateRadioButtonName = string.Format("{0}{1}{2}", "rb_Graduated[", indexValueToUse, "]");
           
 var rbDidYouGraduate = driver.FindElement(By.Id(didYouGraduateRadioButtonName));
            
javaScriptExecutor.ExecuteScript("arguments[0].checked = true;", rbDidYouGraduate);

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.