我正在使用Selenium2Library运行ROBOT Framework。 我有一张有几列的桌子。我想找到此表中的哪一行具有所需的特定文本/输出。对于这种情况,我对第2、3、4、5和6列感兴趣,如下所示。这里的问题是我如何使这个xpath作为单个xpath查询?在这种情况下,此表中有很多行(tr)。
<table>
<tbody>
<tr>
...
<td></td> # column 2 must have this output ->'ROUTE A'
<td></td> # column 3 must have this output ->'ROUTE B'
<td></td> # column 4 must have this output ->'Intermediate'
<td></td> # column 5 must have this output ->'Sent'
<td></td> # column 6 must have this output ->'No'
<tr>..</tr>
<tr>..</tr>
...
答案 0 :(得分:2)
此xpath查询可以单行编写,如下所示。
//table/tbody/tr[(td[2]='ROUTE A') and (td[3]='ROUTE B') and (td[4]='Intermediate') and (td[5]='Sent') and (td[6]='No')]
要在ROBOT Framework中编写:
WAIT UNTIL PAGE CONTAINS ELEMENT xpath=//table/tbody/tr[(td[2]='ROUTE A') and (td[3]='ROUTE B') and (td[4]='Intermediate') and (td[5]='Sent') and (td[6]='No')]
或者我们可以在如下所示的变量中分配结果(布尔值)。
${found}= RUN KEYWORD AND RETURN STATUS WAIT UNTIL PAGE CONTAINS ELEMENT xpath=//table/tbody/tr[(td[2]='ROUTE A') and (td[3]='ROUTE B') and (td[4]='Intermediate') and (td[5]='Sent') and (td[6]='No')]