2015-06-25 100 views
0

我是Robot Framework的新手。我想实现一个For循环来检查页面上的xpath。它应该等待xpath 10秒,如果xpath仍然不存在,那么再等10秒,如果出现xpath,则退出循环并继续前进。总共需要10次迭代才能等待元素。 我想下面:For循环检查Robot Framework中的xpath

|| ${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 // *' 继续 ']' 元素并没有出现在10秒。

如果我错过了一些信息,请告诉我。我正在使用RIDE进行编辑。编辑: 我必须做一个循环。我正在寻求帮助,以便我可以在我工作的其他地方使用此循环示例。

回答

0

您可以通过FOR循环或“等到关键字成功“。

见两个例子:

*** 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 
0

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

+0

感谢您的回答,但我想在一个循环来验证这一点,我要检查它10秒,如果XPath尚未出现,然后等待10秒钟。我可以在其他地方重复使用循环,但有一些不同,这就是为什么我在这里问这个问题。请帮助。 –