# \[Feature\] Conditions in Macros

**URL:** <https://forums.distill.io/t/feature-conditions-in-macros/2586>\
**Category:** Announcements\
**Tags:** conditions, macros\
**Created:** [October 9, 2023, 7:06am UTC](https://forums.distill.io/t/feature-conditions-in-macros/2586 "2023-10-09T07:06:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cobramonk](https://forums.distill.io/user_avatar/forums.distill.io/cobramonk/32/353_2.png) [@cobramonk](https://forums.distill.io/u/cobramonk)\
**Post date:** [October 9, 2023, 7:06am UTC](https://forums.distill.io/t/feature-conditions-in-macros/2586/1 "2023-10-09T07:06:01Z")

</div>

Hi all,

We are excited to announce the release of a new feature in Macros: **Conditionals**.

This introduces a new type of step in Macro, the **Conditional** **(`If..Else`)**. It allows you to execute specific steps based on wether a condition evaluates to `true` or `false`. This is similar to the `If..Else` structure in programming languages.

```auto
if ( this expression evaluates to true) {
    //Execute these of steps
} else if ( this other expression evaluates to true) {
   // Execute these other steps
}

```

**Example Use cases** :

1. **Handling Popups** : On certain page loads, a popup may appear while at other times it doesn’t. If your macro has a step to click on the close button of the popup, it might encounter errors if the popup is absent. To address this, you can set a Conditional to click the popup’s close button only if the popup is present. Reference to a similar query can be found in this thread:

> [@Conditionally skip a macro step?](https://forums.distill.io/t/conditionally-skip-a-macro-step/2496):
>
> The website I’m monitoring sometimes has an initial “Click here to continue” message, and sometimes doesn’t. The times that it does not, my macro, which is set to click the “Click here to continue” button, fails because it doesn’t find that button. Is there any way for that step in my macro to be skipped for the times the button doesn’t show up? But continue to click it for the times that it does show up?

1. **Login if not already logged in** : Execute a list of steps to login, only when you are prompted to login. If you are not prompted to login (because you are already logged in), these steps are automatically skipped.

The following video shows how to use Conditionals to skip a step when not needed.

The content in the demo page is accessible only after user clicks on the `Agree` button. Once _agreed_, the button is no longer visible until the cookie expires. We create a macro that clicks the button when present and skip when it it is not.

[https://www.loom.com/share/bead83d7b2ec46178beac6f275ba7d1e?sid=118f75d1-3402-4b85-84e2-54c92bc8ff81](https://www.loom.com/share/bead83d7b2ec46178beac6f275ba7d1e?sid=118f75d1-3402-4b85-84e2-54c92bc8ff81)

**Please share your thoughts and feedback.**

**Future developments** :

1. Make it easier to move steps in and out of Condition block.

---

<div class="post-metadata">

**Author:** ![chromebeagle](https://forums.distill.io/user_avatar/forums.distill.io/chromebeagle/32/630_2.png) [@chromebeagle](https://forums.distill.io/u/chromebeagle)\
**Post date:** [October 25, 2023, 10:44pm UTC](https://forums.distill.io/t/feature-conditions-in-macros/2586/2 "2023-10-25T22:44:32Z")

</div>

Seems to work well, thank you! I accidentally seem to have reset my Macro to the previously saved version by clicking on the “# steps” and had to redo my entire Condition block, but now that everything is set up properly it seems to be working. Will monitor it over time!

---

<div class="post-metadata">

**Author:** ![rohitch](https://forums.distill.io/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@rohitch](https://forums.distill.io/u/rohitch)\
**Post date:** [November 20, 2023, 5:16pm UTC](https://forums.distill.io/t/feature-conditions-in-macros/2586/3 "2023-11-20T17:16:52Z")

</div>

I wish there a while as well, because the the pop up keeps coming for an uncertain number of times, so I believe a while loop would solve this problem, also what other conditions can we use in the if block, just like you used a button.

---

<div class="post-metadata">

**Author:** ![cobramonk](https://forums.distill.io/user_avatar/forums.distill.io/cobramonk/32/353_2.png) [@cobramonk](https://forums.distill.io/u/cobramonk)\
**Post date:** [November 21, 2023, 5:32am UTC](https://forums.distill.io/t/feature-conditions-in-macros/2586/4 "2023-11-21T05:32:10Z")

</div>

There is plan to add looping too.

> what other conditions can we use in the if block

Currently we have “element\_exists” and “element\_has\_text” for conditions in an If block. More conditions will be added on the basis of need.
