首页 > 解决方案 > Xpath 组合标签或节点

问题描述

<tr id="computer-report-tbl-row-0" ng-repeat="item in table.data.items" class="ng-scope" style="">
    <td id="column-name-0" class="table-cell-md" sc-ellipsis-title="" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
        <a ui-sref="devices.computers-details({id:item.id})" route="devices.computers-details({id:item.id})" href="/manage/devices/computers/b97f242b-2ab6-6472-4926-6ca32301c2de">
            <ng-transclude><span class="ng-binding ng-scope">hello</span></ng-transclude>
        </a>
    </td>
    <td id="column-last-activity-from-now0" class="table-cell-date-age ng-binding">9 months ago</td>
</tr>

当且仅当xpath 包含与AND与和文本时,我想获取<a>标记<td>class = "table-cell-md"<td>class='table-cell-date-age ng-binding'9 months ago

到目前为止,我在想:

//td[@class = 'table-cell-md']|/@*[@class='table-cell-date-age ng-binding' and text()='9 months ago']

标签: htmlseleniumxpath

解决方案


//td[
    @class = 'table-cell-md'
    and following-sibling::td[
        @class='table-cell-date-age ng-binding' and text() = '9 months ago'
    ]
]/a

如果following-sibling::td[1][...]您只想考虑紧随其后的<td>.


推荐阅读