获取匹配Xpath Count关键字不会返回所有匹配的Xpath

时间:2017-06-28 11:45:29

标签: python-2.7 selenium xpath robotframework selenium2library

我正在尝试在我正在处理的页面中存储所有单选按钮的列表。单选按钮数量将根据我的分页号而改变。

现在我正在使用下面的代码查找所有匹配的Xpath并将其存储在变量中。

*** Keywords ***
Count How Many RadioButtons On Page
    ${Count}    Get Matching Xpath Count    //tr
    ${CountList}    Create List
    : FOR    ${INDEX}    IN RANGE    1    ${Count}
    \    Append To List    ${CountList}    xpath=//tr[${INDEX}]
    log    ${CountList}
    Set Global Variable    ${CountList}

这只存储了11个条目。当页面实际包含20.由于某种原因,它缺少其他9,我无法弄清楚原因。

最后,CountList变量如下所示:

u'xpath=//tr[1]', u'xpath=//tr[2]', u'xpath=//tr[3]', u'xpath=//tr[4]', u'xpath=//tr[5]', u'xpath=//tr[6]', u'xpath=//tr[7]', u'xpath=//tr[8]', u'xpath=//tr[9]', u'xpath=//tr[10]', u'xpath=//tr[11]'

此列表应该一直到//tr[20]

我还可以确认使用(例如)//tr[12]或之后,将正常工作。只是因为某些原因,Get Matching Xpath Count并没有全部拉出所有20个。

任何人都能发光吗?

编辑:

以下是我想要计算的页面的HTML的一部分:

<tbody id="oKGQf0-rows">
    <tr id="oKGQ_1" class="z-listitem z-listitem-selected">
        <td id="oKGQ0q" class="z-listcell">
            <div id="oKGQ0q-cave" class="z-listcell-content"><span id="oKGQ_1-cm" class="z-listitem-checkable z-listitem-radio"><i class="z-listitem-icon z-icon-radio"></i></span>&nbsp;P-DAC-15-790</div>
        </td>
        <td id="oKGQ1q" class="z-listcell">
            <div id="oKGQ1q-cave" class="z-listcell-content">DATA</div>
        </td>
        <td id="oKGQ2q" class="z-listcell">
            <div id="oKGQ2q-cave" class="z-listcell-content">..DATA</div>
        </td>
        <td id="oKGQ3q" class="z-listcell" title="AMD Contractors Work Permit">
            <div id="oKGQ3q-cave" class="z-listcell-content">15</div>
        </td>
        <td id="oKGQ4q" class="z-listcell">
            <div id="oKGQ4q-cave" class="z-listcell-content">i9</div>
        </td>
        <td id="oKGQ5q" class="z-listcell">
            <div id="oKGQ5q-cave" class="z-listcell-content">DATA</div>
        </td>
        <td id="oKGQ6q" class="z-listcell">
            <div id="oKGQ6q-cave" class="z-listcell-content">&nbsp;</div>
        </td>
        <td id="oKGQ7q" class="z-listcell">
            <div id="oKGQ7q-cave" class="z-listcell-content">26-06-2015 14:50</div>
        </td>
        <td id="oKGQ8q" class="z-listcell">
            <div id="oKGQ8q-cave" class="z-listcell-content">&nbsp;</div>
        </td>
        <td id="oKGQ9q" class="z-listcell">
            <div id="oKGQ9q-cave" class="z-listcell-content">&nbsp;</div>
        </td>
    </tr>
    <tr id="oKGQ11" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQ31" class="z-listitem">
    </tr>
    <tr id="oKGQ51" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQ91" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQb1" class="z-listitem">
    </tr>
    <tr id="oKGQd1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQf1" class="z-listitem">
    </tr>
    <tr id="oKGQh1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQj1" class="z-listitem">
    </tr>
    <tr id="oKGQl1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQn1" class="z-listitem">
    </tr>
    <tr id="oKGQp1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQr1" class="z-listitem">
    </tr>
    <tr id="oKGQt1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQv1" class="z-listitem">
    </tr>
    <tr id="oKGQx1" class="z-listitem z-listbox-odd">
    </tr>
    <tr id="oKGQz1" class="z-listitem">
    </tr>
    <tr id="oKGQ02" class="z-listitem z-listbox-odd">
    </tr>
</tbody>

EDIT2:

我已将Get Matching Xpath Count更新为//div[4]/table/tbody/tr更具体一点,它仍然只有11,而不是20

EDIT3:

如果我在第二页上执行相同的测试,它完全正常(返回20,并循环20行)但第1页和第2页之间没有区别......

1 个答案:

答案 0 :(得分:0)

事实证明,RF并不真正理解页面内发生了什么。所以我做的是当我到达页面(通过导航栏)然后刷新当前页面。然后它看到了所有20个条目,并按预期继续通过for循环。

我不知道这是否是Selenium2Library的RF中的错误,但在尝试完成逻辑任务时,我不需要基本上重新初始化网页。

如果其他人遇到类似这样的问题 - 请在下方发表评论,并尽力帮助您:)