简体   繁体   中英

Unable to Click on Radio button using Selenium C#

Below is my HTML snippet of my Application. My Scenario is to Click on the Radio button. The xpath which I am using is //input[@id='authorizedContact1'] but still I am unable to Click on the Radio button.

The HTML is:

<div class="radio">
<input id="authorizedContact1" name="authorizedContactValue" class="authorizedContact" type="radio">
<label for="authorizedContact1">
::before ==$0
"YES"
::after
</label>
</div>

Here is is my code which I am using in Selenium

WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(100));
            IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@id='authorizedContact1']")));
            element.Click();

I am using the XPATH as //input[@id='authorizedContact1'] But still unable to Click on the Radio button can anyone Help me in this

Since you need to Click() on the element you need to induce WebDriverWait for ElementToBeClickable() and you can use either of the Locator Strategies :

  • CssSelector :

     new WebDriverWait(_driver, TimeSpan.FromSeconds(100)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("label[for='authorizedContact1']"))).Click(); 
  • XPath :

     new WebDriverWait(_driver, TimeSpan.FromSeconds(100)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//label[@for='authorizedContact1']"))).Click(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM