3

<div class="signup-agreement checkbox-item clearfix" xpath="1">
                <label for="memberContract" ng-class="{'checked': vm.memberContract}" class="checked">
                    <div class="custom-input-wrapper custom-type-checkbox checked" ng-class="{'checked': vm.memberContract}" style="">
                        <input class="customized ng-dirty ng-valid-parse ng-touched ng-not-empty ng-valid ng-valid-required" id="memberContract" name="checkbox_2" type="checkbox" ng-model="vm.memberContract" required="" ng-class="{ 'error': (registerForm.checkbox_2.$invalid &amp;&amp; registerForm.checkbox_2.$touched)}" style="">
                    </div>
                    <div class="checkbox-text" style="">
                        <span translate="CHECKOUT_SUMMARY_MEMBERSHIP_CONDITIONS" style=""><strong style="">Membership Conditions</strong> and <strong>Protecting My Personal Data</strong>I have read and accept</span>
                    <a class="signup-agreement-link" href="javascript:void(0)" ng-click="vm.openAllRegisterContract()">
                        <i class="icon icon-question-mark"></i>
                    </a>
                
            </div>

            <p ng-show="(registerForm.$invalid &amp;&amp; registerForm.$touched)" class="error-message spacing ng-hide">
                Please check the fields mentioned above.
            </p>
        </label></div>

my code:

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

other things i tried: `IWebElement aaa = driver.FindElement(By.XPath("//input[@id='memberContract']"));
                    aaa.Click();

It's a checkbox that I came across when I signed up for the site. I'm stuck here, please help me.

not clicking

Nguyễn Văn Phong
  • 12,566
  • 16
  • 32
  • 51
mahvettin
  • 45
  • 6

1 Answers1

1

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();
    
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281