【发布时间】:2017-12-01 18:14:13
【问题描述】:
我正在尝试在我正在处理的页面中存储所有单选按钮的列表。单选按钮的数量会根据我所在的分页数而变化。
现在我正在使用下面的代码来查找所有匹配的 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> 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"> </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"> </div>
</td>
<td id="oKGQ9q" class="z-listcell">
<div id="oKGQ9q-cave" class="z-listcell-content"> </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:
如果我在第 2 页执行相同的测试,它完全可以正常工作(返回 20,并循环通过 20 行)但是第 1 页和第 2 页之间没有区别...
【问题讨论】:
-
你确认
${Count}是20了吗? -
您能否提供一个您希望从中计算
xpath的代码示例? -
@ILostMySpoon
${Count}包含 12,现在更加混乱!Get Matching Xpath Count计数对吗? -
是的,没错。如果没有您尝试计算的实际
xpath的示例,很难确定问题可能是什么。 -
我正在尝试计算当前页面上的所有
//tr。这应该是 20,而不是 11。或者你的意思是 HTML?
标签: python-2.7 selenium xpath robotframework selenium2library