【问题标题】:How to include an attribute in an XPath selection如何在 XPath 选择中包含属性
【发布时间】:2014-07-18 13:25:30
【问题描述】:

我正在使用 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&currentPage=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&currentPage=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&currentPage=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&currentPage=7';this.form.submit();" disabled>
            </td>

【问题讨论】:

    标签: python selenium xpath


    【解决方案1】:

    试试:

    //*[@name="next"][not(@disabled)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多