> 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/when-the-test-doesnt-work/common-errors/javascript-error.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# JavaScript Error

If an error occurs in a JS step, the following message appears in the test result:

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

The message after "JavaScript error: " gives you a clue as to what the issue is.

Here are some possible causes of JS Step errors and how to fix them.

## The JS Step was executed before the page load was complete

JS Steps are executed without waiting for the page to load. For example, if it's a JS Step that clicks on an element found by a CSS Selector, the step will fail if it's executed before the page has finished loading, since the CSS Selector can't find the element.

Review the screenshots and [video logs](https://help.autify.com/nocode-web/en/autify-university/foundation/test-results/video-logs-for-test-results.md) of the test results. If you see a loading screen or the page is incomplete, it's possible that the JS Step was executed before the page was fully loaded.

In this case, the solution is to add a [sleep step](https://help.autify.com/nocode-web/en/autify-university/foundation/creating-a-scenario/sleep-step.md). Insert a sleep step before the JS Step so that it waits a few seconds for the page to load.

## Causes of Error Messages and Fixes

Next, let's take a look at some common error messages.

### Cannot read properties of null

This error message appears when you try to access a property of an object and the object is `null`. For example, suppose you want to click on an element selected by a CSS selector. If there is no element available in the CSS selector specified in `document.querySelector()`, `null` will be returned. If a `click` is executed on this returned `null`, an error will occur:

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

Please see [this article](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-get-css-selectors.md#how-to-validate-css-selector-xpath) to check if the specified CSS selector can select the correct element.

### xxx is not defined

This error occurs if you try to reference an undefined variable or function. Please ensure that the variable or function is defined.

{height ="" width="500"}

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

### Error: cannot find the element with selector/XPath

Some snippets in [Autify JavaScript Snippets](https://javascript-snippets.autify.com/) use a CSS selector/XPath to select the element before clicking on it. If the specified CSS selector/XPath is incorrect, or if the CSS selector contains dynamic values that change each time the test is run, the element cannot be selected and an error occurs:

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

Please see [this article](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-get-css-selectors.md#how-to-validate-css-selector-xpath) and make sure the specified CSS selector / XPath can select the correct element.

## If you are still having trouble...

Please contact our Customer Support team. We will help resolve the issue.

## Related articles

* [How to get CSS selectors / XPath](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)


---

# 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/when-the-test-doesnt-work/common-errors/javascript-error.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.
