JavaScript Error
  • 30 Aug 2023
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

JavaScript Error

  • Dark
    Light

Article Summary

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

js_error_en

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 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. 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:

cannot_read_properties_of_null

Please see this article 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.

is_not_defined

Error: cannot find the element with selector/XPath

Some snippets in Autify JavaScript Snippets 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:

cannot_find_the_element_with

Please see this article 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.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.