Invoke a js function in Chrome

Hi,

I am facing some issues invoking a js function using InjectJsScript activity.

Invoking the function from the Chrome console works properly:

image

I am using the InjectJsScript activity to invoke the function in this way:

I get this error:

image

Does anyone have any suggestions regarding it?

Thanks in advance,

Hey @joelromero

Try this once,

(function() { 
   //your function call
})();
function (element, input) {
    //your function call
}

Thanks
#nK

Your selector is pointing at a DIV inside the page, rather than the page itself. It’s the same idea as scoping variables in Studio. The JS function isn’t defined (scoped) at the DIV level.

Hi,

Thanks for your response. I have tried using the statements mentioned, as shown:
image

But I keep getting the error that the function is not defined:

I have also tried using the browser and the html body as the target element and having the script in a file but I get always the same result.

Do you have any other suggestion regarding it?

Thanks

Hi @joelromero,

Welcome to the UiPath community!

As @postwick pointed out, do check where you are injecting the javascript. Your DOM needs to be on the entire page. When you use the developer console, you have access to entire DOM, when using a selector on an element, you do not have access to the entire DOM. Once you fix that, use the syntax @Nithinkrishna provided.

If it still fails as you write above, then your verJuris(1) is not a function which you can call both in your chrome console (it shows “undefined”). When the console says undefined, it means there is no callable/accessible function called verJuris(1). Is verJuris a function within your html page with 1 as argument?

Here is an example/sample on how to use Inject JS activity : Use Browser Chrome: Inject JS script is not supported for this element - Help! - #8 by jeevith

Hey @joelromero

It looks like your website doesn’t have the JavaScript function your are trying call !

Thanks
#nK

@joelromero Do you have solution for this issue? I am facing the same issue but haven’t solution yet!