- Print
- DarkLight
If an error occurs in a JS step, the following message appears in the test result:
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:
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.
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:
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.