Inject Js Script 'IFRAME': TypeError: Cannot read properties of null (reading 'children')

Javascript working Fine in Chrome Inspect, but showing error from Inject Js Activity

This is the Script :-
var button_div = document.getElementById(“main-content”)
button_div.children[button_div.childElementCount-1].click();

This is the Error :- Inject Js Script ‘IFRAME’: TypeError: Cannot read properties of null (reading ‘children’)

My guess is it’s not a zero-based index, so using the count - 1 is causing it to try to interact with an object that doesn’t exist.

Please suggest the solution…

Try it without the -1

Or maybe button_div.children isn’t returning anything

var button_div = document.getElementById(“main-content”) is returning empty

@Bhavesh_Batra

Is the id you are searching is correct?

cheers

Yes sir, it is working fine in Chrome Inspect but not in UiPath

Hi,

Can you try to set Page at ExecutionWorld property as the following?

Regards,