> 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-zh/cao-zuo-zhi-nan/blocks/writing-conditions.md).

# 条件编写指南

> ⚠️ 字符串 (String) 的核心规则：对于数据类型为字符/字符串，您必须用双引号 `""` 包裹（例如：`$name = "admin"`）。对于数字则直接填写。

#### 1. 数学比较运算符（仅适用于数字）

* `>` : 大于。（例如：`$count > 5`）
* `<` : 小于。（例如：`$loopIndex < 10`）
* `>=` : 大于或等于。
* `<=` : 小于或等于。

#### 2. 逻辑比较运算符（适用于数字和字符串）

* `=` : 相等。
  * *例如*: `3 = 3` ➡️ `true`
  * *例如*: `"hello" = "hola"` ➡️ `false`
* `!=` : 不相等（等于的否定）。
  * *例如*: `3 != 4` ➡️ `true`
  * *例如*: `"hello" != "hello"` ➡️ `false`

#### 3. 字符串处理运算符（String）

* `contains` : 检查前面的字符串是否包含后面的字符串。
  * *例如*: `"ABCD" contains "AB"` ➡️ `true`
  * *例如*: `"AB" contains "ABCD"` ➡️ `false`
* `!contains` : 检查前面的字符串是否不包含后面的字符串。
  * *例如*: `!"ABCD" contains "AB"` ➡️ `false`
  * *例如*: `!"AB" contains "ABCD"` ➡️ `true`
* `contains "B"`（当单独出现在 B 前面时）：检查变量或字符串是否为空字符串。
  * *结果*: 如果为空返回 `true`，如果包含数据返回 `false`。

#### 4. 检查界面元素的函数（Element）

此函数帮助脚本识别网页上按钮、输入框等的出现，通过 XPath 路径：

* `hasElement(XPATH)` : 当元素存在于页面上时条件为真。
* `!hasElement(XPATH)` : 当元素不存在于页面上时条件为真（`hasElement` 的否定）。

#### 5. 组合多个复杂条件的方法

您可以通过使用逻辑符号和括号 `()` 将多个条件组合在同一行中：

* `&&` : 与运算（所有条件必须同时为真）。
* `||` : 或运算（只需一个条件为真即可）。

编写条件的实际示例：

* *情况 1*: 检查循环次数大于 5 且账户名称包含字符 "abc"：

  ```
  $count > 5 && $name contains "abc"
  ```
* *情况 2*: 检查如果未出现登录按钮（已登录）或错误变量显示字符 "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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/blocks/writing-conditions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
