我想用selenium单击一个输入元素,这是一个复选框,您必须切换才能进一步操作,但它不会像我让selenium找到并单击到目前为止的所有其他元素一样单击该元素
我的代码:
ik_ga_akkoord = wait.until(EC.element_to_be_clickable((By.XPATH, '//span\[contains(text(), "Ik ga akkoord met de")\]')))
ik_ga_akkoord.click()
html部分:
<div class="col-xs-12" ng-show="option.infoLinks || addon">
<p ng-show="!subscriptionSettings.isPreparing" class="" style="">
<label class="font-normal">
<input type="checkbox" id="agree" ng model="subscriptionSettings.termsagreement" value="true" ng-click="toggleConfirmButton()" class="ng-pristine ng-untouched ng-valid ng-empty">
<span class="margin-left">Ik ga akkoord met de
<a class="blue-link" ng- href="https://www.kpn.com/service/mijnkpn/voorwaarden- aanpassen-abonnement-extraopties.htm" target="_blank" href="https://www.kpn.com/service/mijnkpn/voorwaarden- aanpassen-abonnement-extraopties.htm">voorwaarden
</a>
</span>
</label>
</p>
</div>
我希望有人能回答:)
ik_ga_akkoord = wait.until(EC.element_to_be_clickable((By.XPATH, '//span\[contains(text(), "Ik ga akkoord met de")\]')))
您正在定位
<span>
元素。相反,您应该定位 <input>
节点。
见下图:
ik_ga_akkoord = wait.until(EC.element_to_be_clickable((By.ID, "agree")))