Home > Blockchain >  How to click on the radio button with label Yes using Selenium and C#
How to click on the radio button with label Yes using Selenium and C#

Time:12-02

HTML Snapshot:

enter image description here

Element Snapshot:

enter image description here

I want to write xpath for 'Yes' label (Green color mentioned in UI image). I'm new for automation & Please help me to resolve. I have add my HTML code & UI

CodePudding user response:

The is basically an <input> element associated with the <label> with text as Yes and to click() on it you can use either of the following Locator Strategies:

  • XPath:

    driver.FindElement(By.XPath("//label[contains(., 'Yes')]//ancestor::input[1]")).Click();
    

Ideally, you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategy:

  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//label[contains(., 'Yes')]//ancestor::input[1]"))).Click();
    
  • Related