Javascript error: Cannot read properties of null (reading 'renderRoot')

I have a test script where a test step is to click a button using javascript functions.The script works fine when played individually. However when I add to a job and run… it fails at that javascript step and the message is as below

//javascript error: Cannot read properties of null (reading ‘renderRoot’)//

Here is my javascript that is written to click a button

//
document.querySelector(“av-side-menu”).renderRoot.querySelectorAll(“button”)[1].click()

//

Please help.

Hi @mail2dwarak,
If your JS path is valid, please add some kind of a timeout logic for example:

element = document.querySelector(“av-side-menu”).renderRoot.querySelectorAll(“button”)[1];
while (element == null){
element = document.querySelector(“av-side-menu”).renderRoot.querySelectorAll(“button”)[1];
}
element.click;

@Amit.Lacher I tried the example but that shows invalid token error. I am not sure how to handle this exception.
It just fails only when I run the job that has 9 test but the individual test with this test step works fine.

Hi @mail2dwarak,
I am not sure what you mean by invalid token error,
but it sounds like the element has a different locator when you run it as part of a job compared to when you run it as test, it’s very likely that some test in the job causes a change in the dom that is affecting your query selector and failing your step.
during your job add a pause before executing this step, long enough so you will have time to execute your query selector in the dev tools.
I am sure that you will find out it gives you null as well.

It worked @Amit.Lacher. Thanks a lot for the solution. just a simple pause of 5 secs and it worked. :smiley:

@mail2dwarak,
Happy it worked out :smiley:
Feel free to reach out if you need anything.

1 Like