如何在RobotFramework中找到可以找到特定值的行数?

时间:2016-07-29 06:47:16

标签: python-2.7 robotframework selenium2library

我已经写过类似的东西了:

Check privileges for PDTA
    ${end}=    Get Matching Xpath Count    //*[@id="listForm:displayDataTable:tbody"]/tr
    ${start}=    Set Variable    0
    : FOR    ${index}    IN RANGE    ${start}    ${end}
    \    ${status}=    Run Keyword And Ignore Error    Element Should Contain    listForm:displayDataTable:${index}    su    ${index}

日志输出为:

output.html

正如你所看到的,我想得到行数,我可以找到值'su'。该值可以在第6行中找到。变量$ {end}等于表中所有行的数量。

有谁知道如何获得这个号码?也许有一个关键字可以帮助我,不是吗?在此先感谢!!!

2 个答案:

答案 0 :(得分:2)

: FOR    ${index}    IN RANGE    ${start}    ${end}
\    ${Name}=    Get Text    listForm:displayDataTable:${index}
\    ${IsEqual}=    Run Keyword And Return Status    Should Be Equal    ${Name}    Su
\    ${RowNumber}=    Set Variable    ${index}
\    Run Keyword If    '${IsEqual}'=='True'    Run Keywords    Log    Rownumber is ${RowNumber}    AND    Exit For Loop

你可以试试这个。

变量 $ {RowNumber} 获取具有文字“Su”的行号。

答案 1 :(得分:0)

作为FOR循环的一部分,我会添加:

Run Keyword If    '${status}' == 'PASS'    Log    ${index}

如果你需要实际使用它,那么只需设置一个变量或附加到列表变量或其他东西