1

I am trying to select a radio button and input element, it has an id of group and value of In_Group. There are 4 different radio buttons with the same id but different values hence I am trying to select the correct one i am looking for.

<input class="custom-radio" id="group" name="group" type="radio" value="In_Group">

I tried something like this:

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

But the element is not found could someone help me out

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
AutoTester213
  • 2,714
  • 2
  • 24
  • 48

1 Answers1

1

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();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352