While loop implemented

Hello All.
I would like convert the script below ? Thanks
WebElement customer = driver.findElement(By.xpath(“//li[.='” + fullCustomerName.toUpperCase() + “']”));
while (!customer.isDisplayed()) {
WebElement pagination = driver.findElement(By.xpath(“//a[@title=‘Next’]”));

Hi @bayramguney,

Robot framework does have WHILE loops, but really for this it might be overkill.

If all you are wanting to do is wait until the page contains a link that matches the first xpath and then click the second link you can simply do something like this:

    ${fullCustomerName}=    Set Variable    John Doe
    ${fullCustomerNameUpper}=    Convert To Upper Case    ${fullCustomerName}
    Wait Until Element Is Visible    //li[.='${fullCustomerNameUpper}']
    Click Link    //a[@title=‘Next’]

This is using SeleniumLibrary but you could use Browser Library instead if you prefer

Keyword I used:

You don’t really need the Set Variable, you can pass the value in from elsewhere in the test.

Hope that’s what you needed,


Hi Dave,
in my scenario there are the customers in different pages using pagination . if the customer we are looking for is not in the page we need to click right arrow to find. then we clicked on the our customer link. That s the reason i needed loop preferably while. I implemented that way but can be modified with better approach.
Thanks again.
${fullcustomername_upper}= convert to upper case ${fullCustomerName}
${customer}= get webelement xpath://li[.=‘${fullcustomername_upper}’]
FOR ${i} IN RANGE 100
${bool}= is visible ${customer}
IF ${bool}
exit for loop
click element xpath://a[@title=‘Next’]
sleep 1

Hi @bayramguney,

What you have is mostly ok, hopefully you don’t have more than 100 pages of customer names, well if you did you’ll probably want to change the test to search for a customer?

If the application shows the number of pages somehow you could used that for the range value.

you should put this line inside the for/while loop

${customer}= get webelement xpath://li[.=‘${fullcustomername_upper}’]

Currently it’ll only get evaluated once before the loop, your original code looked to be from an Object Oriented language? Keywords in Robot framework typically return values not objects (there are exceptions) mostly it’s strings but also lists and dictionaries, so you probably need to shift mindset to more of a procedural programming mindset when creating robot scripts.

As you’d prefer a while loop, to do this with a while loop, first set a variable (e.g. ${continue}) to true, then you can replace the for with while ${continue} and replace the exit for loop with set ${continue}) to false

Hope that’s helpful,