LOOP STATEMENT - five attempts till it finds an available term

I was trying to find solution on similar topics, but i was not successful.

WebUI.click(findTestObject('Tiger/01-Search/12-SearchTourResult/SearchHotelSource/Source4/HotelSource4Order1ShowHideTours1'))

This object contains combo-xpath, which says find in the results first hotel with data source 4 and click on the first button.

Each button has default state - “check”. When i click on check - it might return the state “reserve” but it could be also “not available” and more states which are not important.

I need to get “reserve” to finish the test case. Sometimes it happens after more attempts (buttons). Depends on the availability of a term.

What would be suitable to use, loop statement FOR ?

If yes, how to write it in the script inside test case.

Lets say i would like to use 5 attempts, till it finds the desired button "reserve"

Usually when i use click on reserve, i just use in object simple
//*[(text() = 'Rezervovat' or . = 'Rezervovat')]

If fifth attempt will fail too, it should be stopped. It usually means that entire hotel is not available at all.

@Martin1 You can use a FOR statement, such as (my preference is the Java format):

int rows_count = 5
Loop:
for (int irow = 0; irow < rows_count; irow++)
{
blah blah
}

Move to the Script tab. You can use either Groovy format or Java format for FOR or WHILE statements. If you get a match before the final loop, then use “break Loop;” to exit your loop.

Thank you :wink: