Having trouble executing JS function with InjectJS

Hello,

I’m building a really simple test case and want to trigger the Javascript function “calculate()” from a simple online calculator (JavaScript Calculator Online). I can do it through the Chrome console and through the buttons but I need to be able to call the function directly.

The most common error I’m getting is “Inject Js Script: ReferenceError: calculate is not defined”.

In my JS file I’ve tested with both:

  • “calculate()”

  • " function trigger(element, input) {
    calculate();
    return “result”;
    }"

Is it even possible to call predefined functions from websites?

Many thanks

1 Like

I am having a similar problem so I built a simple test: It has an InjectJsScript inside of a BrowserScrope which calls this Javascript function.

function(element, inputFromRPA) {
	DoSomething();
	return true;
}

The DoSomething() function is on the page.

And it returns:
RemoteException wrapping UiPath.Core.ElementOperationException: ReferenceError: DoSomething is not defined —> RemoteException wrapping System.Runtime.InteropServices.COMException: ReferenceError: DoSomething is not defined

I have tried placing the DoSomething() function within the < head > and < body > elements, using both Chrome and Edge but to no avail.

Injecting Javascript.zip (18.4 KB)

Any help you can give would be greatly appreciated. Thanks.

Same problem, Inject js not working in edge browser.
How possible to fix it ?

I am also facing same issue while using Inject JS activity. Did you find any solution?