硒复选框未单击
Posted
技术标签:
【中文标题】硒复选框未单击【英文标题】:Selenium checkbox not clicking 【发布时间】:2020-05-11 18:09:56 【问题描述】:<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 && 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 && 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();
这是我在注册该网站时遇到的一个复选框。我被困在这里,请帮帮我。
【问题讨论】:
您可以手动单击此复选框吗?它看起来灰显或禁用。 我可以手动点击。当您尝试单击时,硒是灰色的,但它没有设置刻度线 【参考方案1】:要在所需元素上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();
【讨论】:
他们都没有工作。我不认为这是关于等待。 @mahvettin 查看更新的答案并让我知道状态。以上是关于硒复选框未单击的主要内容,如果未能解决你的问题,请参考以下文章
Android Espresso - 如果未选中,请单击复选框
Jquery Fancyform 和 IE10:单击标签时未选中复选框
Android Espresso - 如果未选中则单击复选框