如何在XPath选择中包含属性
我正在使用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" />
我使用selenium的点击方法来点击下一页,
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>
1 个回答
36
试试这个:
//*[@name="next"][not(@disabled)]