How to combine Wait Until Element Is Visible and Element Should Be Visible

Hi everyone,
I’m studing RobotFramework. I have some problem in Wait Until Element Is Visible and Element Should Be Visible. If i use Element Should Be Visible ,it would be correct in the context i need to assert the visible element but it doesn’t have wait,fails Immediately. If i just Wait Until Element Is Visible , it’s okay but it is out of context assert.
So i think i combine with Wait Until Element Is Visible. Ex:
Wait And Assert Element Visible
Wait Until Element Is Visible ${ELEMENT} timeout=${TIMEOUT}
Element Should Be Visible ${ELEMENT}

But I find this way not optimal because if the element is not visible, it will not continue to Element Should Be Visible. So anyone help me to combine most effectively?
Thanks so much

Hi,

Thing is that if your Wait fails, it means the element is not visible, then obviously the Element Should be Visible will fail too. So the first kwd already give you the state of the element?
I don’t understand why you need the code to run to the second kwd?

Anyway, you could either wrap the first one with a Run Keyword And Continue On Failure to access the second kwd:

Run Keyword And Continue On Failure    Wait Until Element Is Visible    ${ELEMENT} timeout=${TIMEOUT}
Element Should Be Visible    ${ELEMENT}

Or use a Try Except:

TRY
    Wait Until Element Is Visible    ${ELEMENT} timeout=${TIMEOUT}
EXCEPT
    Element Should Be Visible    ${ELEMENT}
END

Then wrap second kwd with Run Keyword And Warn On Failure to avoid test fail.

Regards
Charlie

1 Like

Hi Charlie, thanks for support , My mean if we use the first keyword Wait Until Element Is Visible it will not be correct in the context of assert. i think it is wait. So i want to add Element Should Be Visible for the purpose assert element.but the problem is as you said : element is not visible, then obviously the Element Should be Visible will fail too
I want to find a way to combine these 2 keywords, first wait for the element to be visible, and then check if it is visible or not

Well, maybe something like this then:

${result}    Run Keyword And Return Status    Wait Until Element Is Visible    ${ELEMENT}    timeout=5
IF    ${result}
    Element Should Be Visible    ${ELEMENT}
ELSE
     Fail    Element was not visible after waiting
END

Hey Charile - Could be wrong, but I didn’t think you could chain those two keywords together, as Run Keyword And Return Status doesn’t capture timeouts. So it would still possibly need wrapping in a try-except , at which point that return status keyword is redundant and the except would handle it. So the original try/except is probably best fitted for error handling here, as you suggested first. Happy to be wrong though:slight_smile:

…No idea what library is being used here; Wait Until Element Is Visible exists in a couple of libraries.

Oh yes you’re right :sweat_smile: never tried it though.
But I agree on the redundant check, and honestly thought about Seleniumlibrary at first.

1 Like

I think it is the better way, Charlie

Based on the built-in documentation for Run Keyword And Continue On Failure:

The execution is not continued if the failure is caused by invalid syntax, timeout, or fatal exception.

I’d still opt for a TRY/EXCEPT for error handling in this case. But as Charlie mentions Ive never tried paring the "Run Keyword And… " to see how it handles a keyword that can timeout as well, but if the docs are correct then it will throw an error as opposed to continue given it mentions not handling timeouts

1 Like