---
source_url: "https://help.mabl.com/hc/en-us/articles/23147246313236-Working-with-conditionals"
title: Working with conditionals – mabl help
mirrored_at: 2026-08-04T03:38:47.944Z
host: help.mabl.com
cited_in_42a: true
mirror_canonical: "https://index.42a.ai/help.mabl.com/hc/en-us/articles/23147246313236-Working-with-conditionals"
---

> **Original source:** https://help.mabl.com/hc/en-us/articles/23147246313236-Working-with-conditionals

![](https://help.mabl.com/system/photos/33621633357588/mabl.jpeg)

With conditionals, you can handle testing scenarios that sometimes require action, such as dismissing a consent dialog, completing a verification prompt, or skipping a step when a value is already set. This article explains how to author [conditional steps](https://help.mabl.com/hc/en-us/articles/19078157562644) in the mabl Trainer, including how to…

-   [Add a conditional step](#h_01KP6RE809M6PMC21XW2MP1DY7)
-   [Check multiple conditions before taking action](#h_01KP6RE809TDNF71DYFZC5JN7R)
-   [Take action when any one of several conditions is true](#h_01KP6RE80A604F61ZMVVS5XKT3)
-   [Exit a loop when a condition is met](#h_01KP6RE80A1N5KQTYHCHATT884)

![Conditionally dismissing a privacy popup](https://help.mabl.com/hc/article_attachments/48225428449940)

## Add a conditional step

In the mabl Trainer, take the following steps to add a conditional step:

1.  Click on **\+ (Add step) > Conditionals**.
2.  Select a specific conditional step type: IF, ELSE IF, ELSE
3.  If you are creating an IF or ELSE IF step, choose what you want to base the condition on:
    -   [An assertion](https://help.mabl.com/hc/en-us/articles/19078158566932), including elements, URL, cookie, variable, and visual assertions.
    -   Advanced find assertion using [CSS or XPath](https://help.mabl.com/hc/en-us/articles/19078195962388)
    -   Output from a [JavaScript snippet](https://help.mabl.com/hc/en-us/articles/17750378384916)
4.  Record the steps that you want to run if the condition evaluates to true.

![Conditional step evaluation options](https://help.mabl.com/hc/article_attachments/48226165269908)

Options for an IF step

When you add an IF step, the mabl Trainer adds an ELSE step and an END step by default.

-   If you don’t need the ELSE step, you may delete it.
-   The END step is required. If you delete it, the mabl Trainer adds a warning icon to the conditional step indicating that the statement has no END step.

## Check multiple conditions before taking action

To ensure a _set_ of circumstances is met before executing steps, use one of the following methods to implement IF… AND… logic:

### JavaScript snippet

If your team is comfortable writing and maintaining JavaScript, create an IF step, and set the IF condition based on JavaScript. Write a [snippet](https://help.mabl.com/hc/en-us/articles/19078152382228) to evaluate whether X and Y are true.

### Nested conditionals

Create an IF step to evaluate for the first scenario. Inside the IF step, add another IF step to evaluate for the second scenario. Inside the nested IF step, record the steps that you want to run if both scenarios are true.

In the following example, the test clicks on a search result if it matches the correct categories: “Creating tests” and “Performance tests.”

![if-and-logic.png](https://help.mabl.com/hc/article_attachments/23147265091860)

Using nested IF statements to implement IF… AND… logic

## Take action when any one of several conditions is true

If your test needs to execute steps when one of several conditions is true, use one of the following methods to implement IF… OR… logic:

### JavaScript snippet

If your team is comfortable writing and maintaining JavaScript, create an IF step, and set the IF condition based on JavaScript. Write a [snippet](https://help.mabl.com/hc/en-us/articles/19078152382228) to evaluate whether X or Y are true.

### Combine conditionals

You can also implement IF… OR… logic by combining conditionals:

1.  Create a variable called `either_situation` and assign it the value “false.”
2.  Create an IF step to evaluate for the first scenario.
3.  Add an ELSE IF step to evaluate for the second scenario.
4.  Inside both the IF and ELSE IF blocks, create a variable called `either_situation` and assign it the value “true.” This action updates the value of `either_situation` to `true`.
5.  After the END step, add a new IF step that checks if the variable `either_situation` equals “true.”
6.  Inside the IF step, record the steps that you want to run if either scenario is true.

For example of IF… OR… logic, the following screenshot shows a test that clicks the “SUBMIT” button if the file upload is either records.csv or roster.csv.

![if-or-logic.png](https://help.mabl.com/hc/article_attachments/23147246308500)

Implementing IF…OR…logic with variables and conditionals

## Exit a loop when a condition is met

You can create a de facto while loop that exits the loop when a specific condition is met. See the article on [Using loops > How to exit a loop early](https://help.mabl.com/hc/en-us/articles/19078186843412#h_01HN0HN6CRB6HZ4FJM20JJ6M74) for more information.