![](/img/trans.png)
[英]How to click a checkbox in an alert popup using Selenium C#. The checkbox does not have any xpath. Can't inspect as right click is disabled
[英]XPath Issue: Not able to click on checkbox
我有一個 HTML 表單,我需要在其中單擊復選框,但不知何故它無法單擊復選框,而是單擊鏈接
HTML 元素 - 未單擊復選框時
<div class="form-group">
<input id="chkTermAndCondition" type="checkbox">
<label for="chkTermAndCondition">
I have read and agree to the
<a id="lnkTermsAndCondition" href="javascrip:void(0);">terms and conditions.</a>
</label>
</div>
HTML 元素 - 單擊復選框后
XPAth 使用但不工作並單擊“鏈接”
//*[@for='chkTermAndCondition'] - click on link
//*[@id='chkTermAndCondition'] - This doesn't work
//div[@id='sellerInformationDiv']/div[3]/div/label - click on link
上面的 xpath 都沒有點擊復選框
試試下面的代碼:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].click();", driver.FindElement(By.xpath("//input[@id='chkTermAndCondition']"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.