Search code examples
robotframework

Do-While Loop in Robot Framework using Selenium


I need to test the Load More button using Do-While Loop in Robot Framework using Selenium. I don't know the syntax of do-while so I used a common syntax in the following code.

My Sample Code Logic

do {

    Run Keyword If    Run Keyword And Return Status    Element Should Be Visible   ${PO_FieldLabel}) == FALSE     FAIL Item not loaded Properly

} while (Run Keyword And Return Status    Element Should Be Visible   ${PO_LoadMore_Btn})

My logic is to loop the iteration till the Load More Button ${PO_LoadMore_Btn} is exist. If exist, check the Name Field ${PO_FieldLabel} is exist. Once the Name Field ${PO_FieldLabel} is NOT EXIST, FAIL the test case and skip the loop.


Solution

  • In Robot Framework, there is NO WHILE LOOP, DO-WHILE LOOP. It has only FOR LOOP We can perform the DO-WHILE LOOP using FOR LOOP

    Kindly look the following code

    :FOR    ${i}    IN RANGE    999999
    /
    /     YOUR LOGIC
    /
    /    Exit For Loop If    {bool expression}