【问题标题】:multiple condition check in for loop using robot framework使用机器人框架的多个条件检查循环
【发布时间】:2026-02-02 13:50:01
【问题描述】:

我正在尝试使用机器人框架检查 for 循环中的多个条件,但它永远不会返回 true。

:FOR    ${RowIndex} IN RANGE    0   ${rowscount}    
    ${ColumnText1}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[3]       
    ${ColumnText2}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[4]       
    ${ColumnText3}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[5]       
    ${bStatus}  | Run Keywords |    Should Contain |    ${ColumnText1} and ${ColumnText2} and ${ColumnText3}    | ${VoucherNumber} and ${Voucherdate} and ${VoucherAmount}
    Exit For Loop If    ${bStatus}  

${bStatus} 从不返回 true。

【问题讨论】:

  • 我认为Run KeywordsShould Contain不会返回任何值。根据current docShould Contain“失败”,如果没有找到预期值。
  • @Würgspaß 对不起,是运行关键字并返回状态

标签: robotframework


【解决方案1】:

试试这样的

    :FOR    ${RowIndex} IN RANGE    0   ${rowscount}    
        ${ColumnText1}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[3]       
        ${ColumnText2}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[4]       
        ${ColumnText3}  Get Text    //*[@id='RadSearchGrid_ctl00__${RowIndex}']/td[5]       

       ${bStatus}=   Run Keyword And Return Status   Run Keywords   Should Contain   ${ColumnText1}   ${VoucherNumber}   AND  Should Contain    ${ColumnText2}   ${Voucherdate}   AND   Should Contain    ${ColumnText3}   ${VoucherAmount}

        Exit For Loop If    ${bStatus}  

【讨论】:

  • 它给出了错误:关键字“BuiltIn.Should Contain”需要 2 到 4 个参数,得到 9 个。
  • 已编辑答案,请使用${bStatus}= Run Keyword And Return Status Run Keywords Should Contain ${ColumnText1} ${VoucherNumber} AND Should Contain ${ColumnText2} ${Voucherdate} AND Should Contain ${ColumnText3} ${VoucherAmount}