Home > Enterprise >  How to click on a single element until the element is not visible at all in robot framework
How to click on a single element until the element is not visible at all in robot framework

Time:10-22

I need to click on an element until the element is not visible, it goes of after clicking 30 times at max. So I've been trying out an for loop for this process. But I am completely new to Robot framework so I need some help. Here's my code from which I've been trying.

 ${BUTTON} =    run keyword and return status    element should be visible     ${NextButton}
    FOR    ${BUTTON}    IN RANGE    30
        IF    ${BUTTON} == ${True}    click element    ${NextButton}
        sleep    2s
        ${BUTTON} =    run keyword and return status    element should be visible    ..${NextButton}
        EXIT FOR LOOP IF    ${BUTTON} == ${False}
    END

CodePudding user response:

Use another variable for the loop:

FOR    ${i}    IN RANGE    30

Otherwise, you're constantly reassigning ${BUTTON} to a number, and it's losing its boolean value.


By the way, inside the loop the locator is prefixed with two dots - ..${NextButton - I don't know is that intentional, but doesn't look so.

CodePudding user response:

I cracked the way to make it work, here is what i tried ${BUTTON} = run keyword and return status element should be visible

${BUTTON} =    run keyword and return status    element should be visible    ${ReaderNextButton}
    WHILE   ${BUTTON}
        click element    ${ReaderNextButton}
        sleep    0.5s
        ${BUTTON} =    run keyword and return status    element should be visible    ${ReaderNextButton}
    END
  • Related