> 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/element/get-element-attribute.md).

# Get element attribute

This action helps you "extract" hidden information within an element on the webpage and store it in a variable for later use.

* Effect: For example, you can get the image path from the `src` attribute, or get the link from the `href` attribute of a link tag, or retrieve the input value in the `value` field.
* Simple understanding: Each component on the web has accompanying "attributes" (like an information sticker). This command helps you read and "copy" information from that sticker to save it.

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

#### Explanation of configuration parameters:

* Element XPath: The XPath identifier path of the element containing the attribute to be retrieved on the webpage interface.
* Attribute name: The name of the attribute from which you want to extract data.
  * *Example structure*: `<tag attribute_name="attribute_value">Text</tag>` ➔ You just need to fill in `attribute_name` in this field to get `attribute_value`.
* Output variable: The variable name to store the string value of the attribute after successful retrieval.

#### Practical example: Scraping product image links based on actual images (Figure 5)

Based on the interface of the phone store webpage you are working on in the image, you want to scrape the image path of the Samsung Galaxy S6 phone for data storage or automatic posting to your shop.

Looking at the HTML source code table (red box on the right of the image):

> Image tag structure: `<img class="card-img-top img-fluid" src="imgs/galaxy_s6.jpg" alt="">`

To get the image path string `imgs/galaxy_s6.jpg`, you will configure the action as follows:

* Element XPath: Enter the exact XPath pointing to that image tag, for example: `//div[@class="card h-100"]/a/img` (or use the syntax as in your image: `//div[@class='card h-100']//img`).
* Attribute name: Enter the word `src` *(This is the name of the attribute containing the file path of the image)*.
* Output variable: Name the output variable as `imgUrl`.

Result: The system will locate the image tag of the Samsung Galaxy S6, extract the string value in the `src` attribute, and directly load the value `imgs/galaxy_s6.jpg` into the variable `$imgUrl`. You can use this variable for actions to download images or store them later.

<figure><img src="https://2961903581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpIRrmOLZkhHBXdAiidIw%2Fuploads%2Fgit-blob-e877c15fe9231f74f2294d70b893a3cd40c9e791%2Fel-02.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2961903581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpIRrmOLZkhHBXdAiidIw%2Fuploads%2Fgit-blob-d45458808ef60dfcb6c31a4ec0ac80d3f55932c4%2Fel-02b.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/automate-en/action-guide/element/get-element-attribute.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.
