roger referabal
roger referabal

Reputation: 89

For loop to check for a xpath in Robot Framework

I am a newbie in Robot Framework. I want to implement a For loop to check for a xpath on the page. It should wait for 10 seconds for the xpath, if the xpath is still not there then wait again for 10 seconds, if the xpath has appeared then exit the loop and move ahead. A total of 10 iterations are required to wait for the element. I am trying the below:

|| ${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

I am getting the error right now as: FAIL : Element 'xpath=//*[.='Continue']' did not appear in 10 seconds.

Let me know if I have missed some information. I am using RIDE for editing.

EDIT: I have to do it in a loop. I am asking for help regarding this so that I can use this loop example in other places of my work.

Upvotes: 0

Views: 2632

Answers (2)

Laurent Bristiel
Laurent Bristiel

Reputation: 6935

You can achieve this either with a FOR loop or with a "Wait until keyword succeeds".

See both examples:

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

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 386325

The keyword is failing, so the test case is failing. What you need to do instead is either not use a loop and simply wait for 100 seconds, or use something like Run keyword and ignore error or Run keyword and continue on failure (eg: Run keyword and ignore error | Wait until page contains element | ...)

Upvotes: 0

Related Questions