0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    What is the question? Please edit your post and add it there. – Bogdan Doicin Mar 27 '19 at 15:30
  • Nobody can help you with that little information. Please give more information about the problem, including error messages and/or reproduction steps. – Simon Mar 27 '19 at 15:31
  • Yes, please post the script where you are using that xpath. – C. Peck Mar 27 '19 at 16:11
  • @C.Peck again Edited please check – Rajaram Kannuri Mar 27 '19 at 16:35
  • When you say you’re “unable to click” you mean the “element.Click()” isn’t doing anything? Are you getting any errors? Finally are there any other elements on your page with that id? – C. Peck Mar 27 '19 at 16:41
  • @C.Peck IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//input[@id='authorizedContact1']"))); in this line it is generating TImeout Issue – Rajaram Kannuri Mar 27 '19 at 17:04
  • Clearly the element is not visible.Perhaps there is more than one element with this xPath ? Does element == null ? – SlightlyKosumi Mar 27 '19 at 18:51
  • @SlightlyKosumi Yes you are exactly correct so what is the correct solution for this now – Rajaram Kannuri Mar 27 '19 at 19:17
  • Please someone help me in this today my entire day in office got wasted it will give a very bad impression on me.Please try to help me in this – Rajaram Kannuri Mar 27 '19 at 19:18
  • 1
    Is there more than one input in the html? If not use By.Tag. Else, open DevTools. Hover over the element to get its CssSelector. Try using that instead of its xpath. Try using FindElements instead of FindElement to make sure there are not multiple answers. Check that element is not null before trying to click on it. – SlightlyKosumi Mar 27 '19 at 20:23
  • have you tried to check if `IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[@class='radio']")))` ? And do you see the radio button on the page? Have you tried keeping a break point and check manually and then in console? Are there any frames on the page? – supputuri Mar 27 '19 at 21:41

1 Answers1

0

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