gpt4 book ai didi

c# - Selenium 复选框不点击

转载 作者:行者123 更新时间:2023-12-03 17:59:37 27 4
gpt4 key购买 nike

<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>

我的代码:

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();

这是我在注册网站时遇到的一个复选框。我被困在这里,请帮助我。

not clicking

最佳答案

要在所需元素上使用 click(),您必须为 ElementToBeClickable() 引入 WebDriverWait,您可以使用以下任一方法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();

关于c# - Selenium 复选框不点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59912978/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com