> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-en/action-guide/blocks/writing-conditions.md).

# Guide to writing Conditions

When using control blocks like If, Else if, or While, you need to set up a condition expression for the system to check at runtime. This expression will return a result of True (true) or False (false)

🎥 Watch the tutorial video: [Here](https://youtu.be/L-w9dT8B2DM).

> ⚠️ Core rule about Strings: For data types that are text/string, you must wrap them in double quotes `""` (Example: `$name = "admin"`). For numbers, enter them directly.

#### 1. Arithmetic Comparison Operators (Only applicable to Numbers)

* `>` : Greater than. (Example: `$count > 5`)
* `<` : Less than. (Example: `$loopIndex < 10`)
* `>=` : Greater than or equal to.
* `<=` : Less than or equal to.

#### 2. Logical Comparison Operators (Applicable to both Numbers and Strings)

* `=` : Equal.
  * *Example*: `3 = 3` ➡️ `true`
  * *Example*: `"hello" = "hola"` ➡️ `false`
* `!=` : Not equal (Negation of equality).
  * *Example*: `3 != 4` ➡️ `true`
  * *Example*: `"hello" != "hello"` ➡️ `false`

#### 3. String Handling Operators

* `contains` : Checks if the preceding string contains the following string.
  * *Example*: `"ABCD" contains "AB"` ➡️ `true`
  * *Example*: `"AB" contains "ABCD"` ➡️ `false`
* `!contains` : Checks if the preceding string does NOT contain the following string.
  * *Example*: `!"ABCD" contains "AB"` ➡️ `false`
  * *Example*: `!"AB" contains "ABCD"` ➡️ `true`
* `contains "B"` (When standing alone before B): Checks if the variable or string being examined is an empty string.
  * *Result*: Returns `true` if empty, and `false` if it contains data.

#### 4. Function to Check Element on the Interface (Element)

This function helps the script identify the presence of buttons, input fields, etc., on the webpage via XPath:

* `hasElement(XPATH)` : Condition is true when the element exists on the page.
* `!hasElement(XPATH)` : Condition is true when the element does not exist on the page (Negation of `hasElement`).

#### 5. How to Combine Multiple Complex Conditions

You can combine multiple conditions in one line using logical symbols and parentheses `()` to group:

* `&&` : AND (All conditions must be true simultaneously).
* `||` : OR (Only one of the conditions needs to be true).

Practical examples when writing conditions:

* *Case 1*: Check if the number of iterations is greater than 5 and the account name contains the text "abc":

  ```
  $count > 5 && $name contains "abc"
  ```
* *Case 2*: Check if the Login button does not appear (already logged in) OR the error variable is displaying the text "true":

  ```
  !hasElement(//div[@id='x']) || $error = "true"
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gpmautomate.com/automate-en/action-guide/blocks/writing-conditions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
