【问题标题】:Selenium: Is possible to get the text between two xpath selections?Selenium:是否可以在两个 xpath 选择之间获取文本?
【发布时间】:2012-09-19 20:08:21
【问题描述】:

我有:

<center><h3>Title</h3></center>
...
stuff here that I want selected in <p>...</p>elements
...
<a href="index.htm">Content</a>

我可以使用 xpath 找到它们的第一个和最后一个://center/h3//a[@href="index.html"]

我可以在这两个 xpath 选择之间获取区域吗?如果可以,我应该在该页面的源代码上使用正则表达式吗?

【问题讨论】:

    标签: python regex xpath selenium


    【解决方案1】:

    看看this link,这是一种使用following在两个xpaths之间进行选择的方法。

    这是工作代码:

    //p[preceding::center/h3 and following::a[@href="index.htm"]]
    

    【讨论】:

      【解决方案2】:

      试试//a[@href="index.html"]/../p

      【讨论】:

        猜你喜欢
        • 2021-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-19
        • 2023-03-31
        相关资源
        最近更新 更多