How to excute else block if if condition get failed

hi i am new at robot framework
i want to check button present in ui or not if present then performed certain operation
in else block i want write certain positive conditon means button is not visiable
${element}= Convert To String ${element.content}
IF ${element}
Should Be Equal ${element} ${Responce}
ELSE
Wait Until Element Is Not Visible ${loc__Validation}
Unselect Frame
END

in these condtion test get pass but if the if condtion fail that time else condtion can not run i want run else condition also

Try to use the Run Keyword and Return Status keyword. In this case what I normaly do is:

${CheckButon} Run Keyword and Return Status Element Should be Visible locator
IF ${CheckButon} == True
Comand 1
Comand 2

ELSE
Comand 1
END

2 Likes

Thanks
hi @joseilton
${headers}= Create Dictionary Apikey=${apikey} Username=${userid}
Create Session session https://${environment}-api.${extension}
${response}= RequestsLibrary.GET On Session session ${premium_url} headers=${headers}
${responce1} Convert To String ${response.content}
${body} evaluate json.loads($edition) json
[Return] ${body}
# Get body as dict
${message} = Get From Dictionary ${body} bank_stock
Log To Console ${message} (output {‘stock’: ‘premium’})
${locator_checkbutton_} =//*[contains (text(),‘Check button’)]
in if block now i have write condition if stock is premium then check button is
visible
and in else condition is like if stock is not premium then check button is not visible
please help how to right it

Basically what joseiliton has provided is what you need to apply from the sounds of it… and you can make use of the Wait Until Element Is Visible or any of the other visible keywords

${chk_btn_is_visible}=   Run Keyword and Return Status   Wait Until Element Is Visible   //foo   
IF  ${chk_btn_is_visible}  
    No Operation      # YAY! Stock is premium.. do something 
ELSE
    No Operation      # BOO...! Stock is not premium.. do something 
END

or… as you’ve not really said if there’s a way to identify if a stock item is of type premium, you could do something like below:

IF  {stock_is_premium}
    Element Should Be Visible   //foo   Premium stock should show a check button, but the button doesn't show.  
ELSE
    Element Should Not Be Visible   //foo   None premium stock should not show the check button, but the button shows. 
END

Hard to gauge… really depends on your needs…

1 Like