# How to excute else block if if condition get failed

**URL:** <https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119>\
**Category:** Robot Framework\
**Created:** [2 January 2023 13:09 UTC](https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119 "2023-01-02T13:09:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul12](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rahul12](https://forum.robotframework.org/u/rahul12)\
**Post date:** [2 January 2023 13:09 UTC](https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119/1 "2023-01-02T13:09:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joseilton](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@joseilton](https://forum.robotframework.org/u/joseilton)\
**Post date:** [5 January 2023 10:04 UTC](https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119/2 "2023-01-05T10:04:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rahul12](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rahul12](https://forum.robotframework.org/u/rahul12)\
**Post date:** [5 January 2023 13:30 UTC](https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119/3 "2023-01-05T13:30:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [6 January 2023 16:33 UTC](https://forum.robotframework.org/t/how-to-excute-else-block-if-if-condition-get-failed/5119/4 "2023-01-06T16:33:03Z")

</div>

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…
