我正在尝试使用xpath
编写一个selenium脚本来单击
复选框,但无法执行该操作,而是收到错误
Element is not clickable at point (210.5, 616). Other element would receive the click: Command duration or timeout: 75 milliseconds
html:
<div style="float:left;">
<label class="enhanced-checkbox" for="lender_user_privacy">
<i class="icon"/>
</label>
<input id="lender_user_privacy" class="ui-helper-hidden-accessible" type="checkbox" value="1" required="required" name="lender_user[privacy]"/>
</div>
x路径:
driver.findElement(By.xpath("//input[@id = 'lender_user_privacy']")).click();
注意:您能否建议我正确的 xpath
来单击复选框,因为当我编写上述 xpath
最佳答案
考虑到注释,要导航回父级,您可以使用 xpath 的父级表达式 /..
。
如果 .//input[@id='lender_user_privacy']
正在识别您的标签,即“复选框的子项”,那么您可以使用访问该复选框
.//input[@id='lender_user_privacy']/..
作为你的xpath。但是,考虑到您收到的错误,等待很可能是必要的。
关于javascript - 用于识别复选框的正确 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38991047/