python - 如何在 XPath 选择中包含属性

标签 python selenium 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&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>

最佳答案

尝试:

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

关于python - 如何在 XPath 选择中包含属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24826130/

相关文章:

python - 带逗号的 PySpark 值不包含逗号? (尝试转换为 ArrayType(StringType()))

python - 如何在 python XPath 中连接 br 中的字符串?

python - 在 Dreamhost 上安装和编译 Python、Django、Virtualenv、Mercurial、Git、LessCSS 等的脚本

python - 为什么我在发送 post 请求时收到 "Method not Allowed (HTTP CODE 405)"?

python - 使用boto3下载Lambda函数的部署包

python - webelement.text 不起作用(浏览器 = webdriver.Firefox)

c# - 无法使用 selenium 网络驱动程序 : ElementNotVisibleException 单击 Angular-JS 按钮

selenium - Gradle/Spock/Geb org.openqa.selenium.firefox.NotConnectedException在Linux上可在Windows上使用

xpath - Xpath:基于父值的查询中的异常

xml - 哪种XQuery表达式将返回找到的每个节点的XPath?