> 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/huong-dan-cac-action/element/count-element.md).

# Count element

Hành động này giúp tool quét trên trang web xem có bao nhiêu mục khớp với cái "tên" (XPath) mà bạn đã cung cấp, sau đó lưu con số tổng cộng đó vào một biến.

* Tác dụng: Rất hữu ích khi bạn muốn kiểm tra số lượng sản phẩm đang hiển thị, đếm số comment, hay kiểm tra xem một danh sách đã tải đủ dữ liệu chưa. Nếu đếm được 0 thì tức là không thấy mục nào, nếu đếm được nhiều hơn 0 thì bạn có thể dùng các vòng lặp để xử lý lần lượt từng mục đó.

🎥 Xem thêm video hướng dẫn: [Tại đây](https://youtu.be/AwlJt1TG80U).

#### Giải thích các tham số cấu hình:

* XPath: Đường dẫn mã định danh (XPath) của tập hợp các phần tử bạn muốn đếm số lượng trên giao diện trang web.
* Output variable: Tên biến số để lưu lại kết quả số lượng đếm được (Trả về một số nguyên: `0`, `1`, `2`, `3`,...).

#### Ví dụ thực tế: Đếm tổng số sản phẩm đang hiển thị trên trang cửa hàng

Khi bạn truy cập vào trang cửa hàng điện thoại như trong hình, bạn muốn kịch bản tự động kiểm tra xem trên trang hiện tại đang hiển thị bao nhiêu sản phẩm để thiết lập số vòng lặp tương tác hoặc cào dữ liệu cho chính xác:

Nhìn vào cấu trúc mã nguồn, mỗi một ô sản phẩm đều nằm chung trong một khối thẻ `div` có thuộc tính `class="card h-100"`. Bạn cấu hình hành động như sau:

* Element XPath: Nhập đường dẫn XPath chung của các ô sản phẩm: `//div[@class="card h-100"]`
* Output variable: Đặt tên biến đầu ra là `totalProducts`.

Kết quả: Hệ thống sẽ quét toàn bộ trang web và đếm xem có bao nhiêu thẻ khớp với XPath trên. Ví dụ trên màn hình hiển thị 9 sản phẩm, biến `$totalProducts` sẽ nhận giá trị là `9`.

> 💡 Ứng dụng nâng cao: Bạn có thể sử dụng biến số lượng này để truyền vào cấu hình của vòng lặp For, giúp kịch bản tự động lặp đúng `9` lần để click xem chi tiết hoặc cào đủ thông tin của cả 9 sản phẩm mà không bị thừa hay thiếu sót.

<figure><img src="https://275605936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FN9cKpvJdcLU6FS8VMSTs%2Fuploads%2Fgit-blob-a8e58c7e4b488e625b1251aa6f5ea4d3ba57550d%2Fimage%20(186).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://275605936-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FN9cKpvJdcLU6FS8VMSTs%2Fuploads%2Fgit-blob-793128dd933faa13db880f95bc39e02a7f6c814b%2Fimage%20(187).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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/huong-dan-cac-action/element/count-element.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.
