> 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/tips-for-using-the-js-step.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Tips on using JS Steps

One of the advantages of Autify is that you can use it without coding, but if something cannot be verified using Autify's features, you may be able to verify it using a JS Step. On this page, you will find examples of when to use JS Steps and some useful tips.

## Introduction

### When should you use JS Steps?

You can use JS Steps for [actions that cannnot be recorded](https://help.autify.com/nocode-web/en/autify-university/foundation/creating-a-scenario/important-points.md#frequently-requested-features) using the Autify Recorder or for complex verifications. For example, a JS Step is an effective solution in the following situations:

* [Verify the absence of a specific element (other than a string)](https://help.autify.com/nocode-web/en/faq/faq-create-scenario/faq-assertion/is-it-possible-to-test-the-absence-of-a-specific-element.md)
* Validate the style of an element
* Run an external API in a scenario

However, it can be challenging to know what you can and can't do with a JS Step until you get used to it. If you are unsure if something can be verified using Autify's features or if a JS Step is appropriate, please contact our support team.

### How to use JS Steps

Please read the following article to learn more about JS Step's functionality and how to add them to your test scenarios: [JS Step](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/javascript-steps.md)

### Prerequisites

To try the methods described on this page, you'll need to be able to get CSS selectors using tools such as Chrome's Developer Tools. If you do not know how to get CSS selectors, please read the following document first:

* [How to get CSS selectors](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-get-css-selectors.md)
* [Using CSS selectors effectively](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-use-css-selectors-effectively.md)

## Examples of using JS Steps

To illustrate how you can use JS Steps, we will show you a test that uses a JavaScript snippet provided by Autify. \*The following examples assume that you have already created a test scenario. If you have not done so, please record a new scenario before proceeding.

### 1. Click element

If you cannot click an element for some reason, you can use a JS Step to do so. For example, let's try using a JS Step to click on the **Request a Demo** button on [Autify's homepage](https://autify.com).

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-eb89952f52553273dfc7375cfa770db43ea66583%2FEn_1_apply_demo.png?alt=media)

**1. Get a CSS selector.** First, we need to get the selector of the element we want to click. In this example, we've used Chrome's Developer Tools to get the selector.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-0cc6c6b5d4915a994b9f7de2a4bf34cf35057a2c%2FEn_1_get_demo_button_selector.png?alt=media)

The selector for this example was:

```
#requestdemo > div > div.web-application-form.mx-auto > form > div > div:nth-child(4) > div > div > button
```

**2. Add a JS Step.** Add a JS Step to the appropriate location.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-83d0d00b7ff6b1ac53def18679fd6d95c0623cf1%2FEn_add_JS_step.png?alt=media)

**3. Add the snippet code for "click element" to the JS Step.** Copy the snippet code for [click element](https://javascript-snippets.autify.com/snippets/mouse/click/) and paste it to the JS Step you created in step 2.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-9c10997ee1b45c8e193972744aa98d33963b500a%2FEn_add_JS_snipet.png?alt=media)

**4. Edit the content of the JS snippet.** In this snippet, there's a section that says \<TODO: REPLACE SELECTOR>. Rewrite this section as follows:

```
"#requestdemo > div > div.web-application-form.mx-auto > form > div > div:nth-child(4) > div > div > button"
```

Once you save the scenario, you can check that the action written in the JS Step is performed by using Local Replay or by running the scenario. In this example, we know that the "Request Demo" button was clicked as intended because errors have appeared in the required fields.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-27e89241ea5eefc5a8356f104e3c5e598a9e4515%2FEn_1_Result.png?alt=media)

### 2. Use data of an element in another step

#### 2-1. Use data of an element as an input value in another step

You can get data of an element and use it as an input value in other steps. This is useful in situations where a unique number of displayed data (e.g., application number) is used to search for data. In this example, we will get the text of the "Ready to Autify your web app testing?" element using a JS Step and use it as an input value for the "Last Name" field.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-296ab806796a20b442a12d1969c582e3ab6219d2%2FEn_2_1_ready_auto_test.png?alt=media)

**1. Get the CSS selector of the element from which you want to get the data** As with the first example, I have used Chrome's Developer Tools to get the CSS selector.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-570e184b70bf4fa6cd1033d832b46b2e8c58c0a6%2FEn_2_1_get_selector.png?alt=media)

In this case, the selector I got was:

```
#requestdemo > div > h3
```

**2. Add a JS step.** Add a JS Step that gets the element's text.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-83d0d00b7ff6b1ac53def18679fd6d95c0623cf1%2FEn_add_JS_step.png?alt=media)

**3. Add the snippet code of "get text content" to the JS Step** Copy the snippet code of [Get text content](https://javascript-snippets.autify.com/snippets/values/get_text_content/) and paste it into the JS step you created in step 2.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-c109880adc4f9ad01f30d7d059898c4dc9f89fca%2FEn_2_1_JS_snipet.png?alt=media)

**4. Edit the content of the JS snippet.** In this snippet, there's a section that says \<TODO: REPLACE SELECTOR>. Rewrite this section as follows:

```
"#requestdemo > div > h3"
```

**5. Record a step that enters the value to the appropriate element.** \*The input value can be any value - we will changed it later.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-b20d40f8fc4f99a97a9852cbeb4558698f61c9ab%2FEn_2-1_recording_step.png?alt=media)

**6. Open the edit screen of the step you added in step 5 and specify that the input value should be the value from the JS Step.** Select **Other step's result** in the Input Value section, and specify the JS Step to which you added the "Get text content" snippet.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-3a0bdf6189ed5208e25d510d6f77b3f3b25cbfd8%2FEn_2-1_change_value.png?alt=media)

After saving the scenario, you can check that the action written in the JS Step was performed by using Local Reply or running the scenario:

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-38d1a28b9487384b266075585364824912c6c95f%2FEn_2-1_test_result.png?alt=media)

#### 2-2. Use an element's data as an expected value in another step

You can get an element's data and use it as an expected value in other steps. This is useful when you want to get a unique number of displayed data (e.g., membership number) and check that it exists on the screen on another step (e.g., page after login). In this example, we will add a step to the scenario used in section 2-1 to check if the correct value was entered.

**1. Add an assertion that validates the value of the target element.** In the scenario we used in section 2-1, add an assertion that checks the value in "Last Name".

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-17b9bef48da2dbcb7b1a20aae8a4e00c65374a97%2FEn_2-2_recordingstep-1.png?alt=media)

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-64e0e63c4ef31ef90d458e93c6a01a31026b48ce%2FEn_2-2_recording_steps.png?alt=media)

**2. Open the edit screen of the step you added in 1 and specify the expected value as the one from the JS Step.** In the expected value section, select **Other step's result** and specify the JS Step to which you added the "Get text content" snippet.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-c7d29aea42da6f327e6b82a76694ca78b4c1715a%2FEn_2-2_change_value.png?alt=media)

After saving the scenario, you can check that the action written in the JS Step is performed by running the scenario:

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-b37eeac7f601c48731289e510405449fe7465c92%2FEn_2-2_testresult.png?alt=media)

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

Assertions are not executed in Local Replay. Please run the scenario to check that the assertion works correctly.
{% endhint %}

### 3. Request API using a JS Step

The JS Step can also be used to send a request to an API. This is useful if you want to get information from an API or call the API within a scenario. In this example, we will add a JS Step that executes an API that returns "Hello Autify!" when you send a GET request.

**1. Add a JS Step.** Add a JS Step to the appropriate location.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-83d0d00b7ff6b1ac53def18679fd6d95c0623cf1%2FEn_add_JS_step.png?alt=media)

**2. Write the code for the "Send GET / POST request synchronously" snippet into the JS Step.**

Since we will be using a GET request, please use the "Send GET request to a URL" snippet which can be found in [Send GET / POST request synchronously](https://javascript-snippets.autify.com/snippets/others/xhr_get_post/).

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-4ed3e087b0768ba8ba30e7a768e5417c5014db86%2FEn_3_JSsnipet.png?alt=media)

**3. Change the URL** Rewrite the following part of the snippet so that it's appropriate for the API you're using:

```
var url = "API URL";
```

After saving the scenario and using Local Replay or running the scenario, the result from the GET request is output to the browser log:

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-8f10ba64f4bcda2d8655ef5a14bc87ba4ae5bc4a%2FJa_%E4%BE%8B3%E5%AE%9F%E8%A1%8C%E7%B5%90%E6%9E%9C\(1\).png?alt=media)

※Note that the provided JS snippet assumes that the response is in JSON format. Depending on the API response format, the JS Snippet may need to be modified.

## Other ways to use JS Step

### Debugging JS Step

There are several ways to debug JS Steps. In addition to running the actual scenario and using Local Reply, you can also use Chrome's Developer Tools to debug. You can easily test the contents of the JS Step you have created, so please try it out. For example, to test the behavior of the JS snippet we used in "1. Click element" using Chrome's Developer Tools, follow the steps below:

**1. Open the page to be tested.** First, open the target page where the JS Step will be executed. You can do this manually or by using Local Replay.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-5b89a7ef6357b5599beffb8077dfb8a6ed298e6e%2FEn_debug0.png?alt=media)

**2. Launch Chrome Developer Tools.** In the example below, Developer Tools is launched by clicking the kebab menu (︙) in the top right corner of Chrome.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-1f9314f12e3f92b8a888df4d2f0c826bd6f11213%2FEn_deug1\(1\).png?alt=media)

**3. Open the Console tab.** In the Developer Tools, open the Console tab.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-81720beab3717a55901f117cad149c9c6d80b6b5%2FEn_debug2.png?alt=media)

**4. Execute the source code of the JS Step in the Console tab.** Execute the source code of the JS snippet in the Console tab.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-bb5b4780b04a41943141752333a8217e17941518%2FEn_debug_4.png?alt=media)

**5. Check that the element was clicked.** We can see that the "Request Demo" button was clicked as intended, because there are input errors in the required fields.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e43cd18c6c448a01809ffc610e647f6f9c2139ef%2FEn_debug3.png?alt=media)

If you have any questions about using JS Steps, please contact our support.


---

# 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/tips-for-using-the-js-step.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.
