如何识别具有相同价值的网络元素?

时间:2017-06-21 22:14:51

标签: css xpath selenium-webdriver

<div class="slimScrollDiv" style="position: relative; overflow: visible; width: auto; height: 435px;">
    <ul class="key-list member-list" data-section="all" style="overflow: hidden; width: auto; height: 435px;">
        <li class="row key-border single" data-name="TP2 - R1" data-id="2877523" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R1" data-session="{"session_id":"F_1_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="TP2 - R2" data-id="2877524" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R2" data-session="{"session_id":"F_2_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="TP2 - R3" data-id="2877525" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R3" data-session="{"session_id":"F_3_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="TP2 - R4" data-id="2877526" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R4" data-session="{"session_id":"F_4_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="TP2 - R5" data-id="2877527" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R5" data-session="{"session_id":"F_5_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="TP2 - R6" data-id="2877528" data-hidden="No" data-modified_timestamps="1498070218" data-desc="TP2 - R6" data-session="{"session_id":"F_6_12_0","instance_id":124122}">
        <li class="row key-border single" data-name="Bottom Door" data-id="2877529" data-hidden="No" data-modified_timestamps="1498070218" data-desc="Bottom Door" data-session="{"session_id":"F_1_7_0","instance_id":124122}">
        <li class="row key-border single" data-name="Top Door" data-id="2877530" data-hidden="No" data-modified_timestamps="1498070218" data-desc="Top Door" data-session="{"session_id":"F_2_7_0","instance_id":124122}">
    </ul>

enter image description here

我必须为搜索图标编写Xpath / CSS,但页面上有多个搜索图标。

1 个答案:

答案 0 :(得分:0)

我想,您希望选择具有li标记的控件,这些控件具有data-name,data-id,data-hidden属性的随机值。在这种情况下,当没有其他合适的方法来唯一标识控件时,您可以使用谓词来选择所需的控件。例如,如果要选择第三次出现li,可以使用以下xpath:

//div[@class='slimScrollDiv']/ul/li[3]

同样,如果你必须选择第七次出现li,你可以使用以下xpath:

//div[@class='slimScrollDiv']/ul/li[7]

让我知道,它是否适合您或我误解了您的问题。