我正在使用 selenium 在页面中移动。
页面源码如下:
<td colspan="10" align="right">
<input type="button" name="previous" value="Previous" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?previous=true¤tPage=6';this.form.submit();" >
<input type="hidden" name="currentPage" id="currentPage" value="6" />
<input type="button" name="next" value="Next" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?next=true¤tPage=6';this.form.submit();" >
</td>
<td colspan="10" align="right">
<input type="button" name="previous" value="Previous" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?previous=true¤tPage=7';this.form.submit();" >
<input type="hidden" name="currentPage" id="currentPage" value="7" />
我正在使用 seleniums click 方法来点击下一页,
browser.find_element_by_xpath('//*[@name="next"]').click()
现在,当我到达最后一页(下面是源代码)时,我得到了相同的 xpath(用于下一页链接)--- 最后带有属性 disabled
。我希望 selenium 停在这里。
但是我不确定如何在 xpath 中包含 disabled
属性。
<input type="button" name="next" value="Next" onclick="this.form.action = 'coca-cola-north-america-group-company-37452.htm?next=true¤tPage=7';this.form.submit();" disabled>
</td>
最佳答案
尝试:
//*[@name="next"][not(@disabled)]
关于python - 如何在 XPath 选择中包含属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24826130/