mahvettin
mahvettin

Reputation: 53

Selenium checkbox not clicking

Selenium checkbox not clicking problem

name="checkbox_2" type="checkbox"

my code:

IWebElement checkbox = driver.FindElement(By.Name("checkbox_2"));
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("arguments[0].click();", checkbox);`

Upvotes: 4

Views: 165

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

To click() on the desired element you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.signup-agreement.checkbox-item.clearfix > label[for='memberContract'] input.customized.ng-dirty.ng-valid-parse.ng-touched.ng-not-empty.ng-valid.ng-valid-required#memberContract"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='signup-agreement checkbox-item clearfix']/label[@for='memberContract']//input[@class='customized ng-dirty ng-valid-parse ng-touched ng-not-empty ng-valid ng-valid-required' and @id='memberContract']"))).Click();
    

Upvotes: 1

Related Questions