How to click on the radio button through the element ID attribute using Selenium and C#

To locate the element you can use either of the following Locator Strategies:

  • CssSelector:

    driver.FindElement(By.CssSelector("input#group[value="In_Group"]"));
    
  • XPath:

    driver.FindElement(By.XPath("//input[@id='group' and @value="In_Group"]"));
    

However, as it is a <input> element and possibly you will interact with it ideally you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.custom-radio#group[value="In_Group"][name="group"]"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@id='group' and @value="In_Group"][@class="custom-radio" and @name="group"]"))).Click();
    

Leave a Comment