For 循环检查 Robot Framework 中的 xpath

For loop to check for a xpath in Robot Framework

我是机器人框架的新手。我想实现一个 For 循环来检查页面上的 xpath。它应该为 xpath 等待 10 秒,如果 xpath 仍然不存在则再次等待 10 秒,如果 xpath 已经出现则退出循环并继续前进。等待元素总共需要 10 次迭代。 我正在尝试以下操作:

|| ${count}= | Get Matching Xpath Count | xpath=//*[.='Continue'] |
|| :FOR       | ${loopIndex}            | IN RANGE                | 10
              | Wait Until Page Contains Element | xpath=//*[.='Continue'] |    10
              | Exit For Loop If        |   ${count}>0  
|| Log          | Got out of loop

我现在收到的错误是: 失败:元素“xpath=//*[.='Continue']”在 10 秒内未出现。

如果我遗漏了一些信息,请告诉我。我正在使用 RIDE 进行编辑。

编辑: 我必须循环进行。我正在就此寻求帮助,以便我可以在我工作的其他地方使用这个循环示例。

关键字失败,所以测试用例失败。你需要做的是要么不使用循环,只需等待 100 秒,要么使用类似 Run keyword and ignore error or Run keyword and continue on failure 的东西(例如:Run keyword and ignore error | Wait until page contains element | ...

您可以使用 FOR 循环或 "Wait until keyword succeeds" 来实现。

查看两个示例:

*** Test Cases ***
test with for loop
  :FOR  ${loopIndex}  IN RANGE  10
  \  ${element_is_here} =  Run Keyword and return status  Page should contain element  xpath=//*[.='Continue']
  \  Exit For Loop If  ${element_is_here}
  \  sleep  10s
  Log  I found the element

test with WUKS
  wait until keyword succeeds  10s  10s  Page should contain element  xpath=//*[.='Continue']
  Log  I found the element