> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/js-steps-for-elements.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# JS Steps for Elements

In JS Steps, there are often situations where your operation is achieved by the following steps.

* Select an element
* Interact with the selected element

In the past, it was always necessary to select an element in a JS step using `querySelector()` or similar methods, but now there is another way to **select an element from the screen and pass it as an argument to the JS step**. Using this method, you no longer need to write CSS selectors or XPaths to select elements to be handled in a JS step!

The usage is as follows:

1. Start recording with Autify Recorder
2. Navigate to the page that includes the target element
3. Right click (Or `Ctl + Click` on Mac) on the element
4. Click `Add JS step` in the context menu

   ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-706cf1c664f36a73f4495073c4b3ead8d55f1ee6%2FScreen%20Shot%202022-08-17%20at%206.29.18.png?alt=media)
5. Click `Save` on the Recorder

Now you have a new JS Step with an argument, `element`. This is the element selected while recording, and you can implement whatever you want to do on this `element` with a plain JavaScript.

The following example triggers double click on the selected element. You may notice that the code for selecting elements is no longer needed:

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e99395c201caa44bd5bb0ab92a609dd4b5dc012c%2FScreen%20Shot%202022-08-17%20at%206.37.08.png?alt=media)

One of the great things that JS Steps for Elements offer is that **the target elements can be found even after the site structure slightly changes**, as AI works on finding this element. This is in contrast to the need to update JS Steps when the complete matching element with the specified CSS selector or the XPath is no longer available. This would significantly reduce the cost of maintenance required for JS Steps!

{% hint style="warning" %}
**Note**

* When recording at mobile size (375x812), to add a "JS steps for elements," you need to first click on the target element to focus it, and then add a "JS steps for elements." During this process, an unnecessary click step will be recorded, so please delete this step.
  * Immediately after finishing local replay, if you add a "JS steps for elements" without clicking on the target element, the step will not be added to the scenario.
  * If you add a "JS steps for elements" without clicking on the target element after clicking on another element, a "JS steps for elements" for the other element will be added.
* If you want to select elements under specific rules without relying on AI, such as always specifying the Nth element, this feature may not be suitable for use. You may want to continue to specify elements with CSS selectors or XPath in such cases.
  {% endhint %}


---

# 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://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/js-steps-for-elements.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.
