Execute Webpages' Existing Javascript

I have a website I am automating that has some built-in javascript code. The code is executed similar to links, where it’s essentially on-click. I’ve found the invoke js activity, which from what I can see lets me execute my own javascript code, but how can I just execute javascript that already exists on a webpage? In this example, I don’t need to inject a script.

Here is an example of what I am trying to interact with:

<a href="javascript:testJavascript('231231', '2','');" style="margin-top:2px; display:inline-block;">
									<img class="vmid" src="https://txt.testscript.com" alt="">
								</a>

Prior to this, I’ve used ui.vision. In ui.vision I can interact with that javascript by using the execute script function of ui.vision. I’m hoping UiPath has something similar. Below is a sample of how it’d be done with ui.vision.

 {
      "Command": "executeScript",
      "Target": "testJavascript('231231', '2','');",
      "Value": "",
      "Description": ""
    },

My goal is to be able to replace the “231231” with a dynamic value via a variable, but otherwise I would just use the existing JS code on the website. Hopefully someone can help point me in the right direction.

@jlpath

Check this out

Alternately you can get the element and send a click to it in inject js

Cheers

Thanks, i did see that video, but that seems to be injecting new code into the page. For my purpose the code is already present, its part of the page, and i am just trying to call an existing function.

Click wont work because the element isnt always visible. Its a multi-page list, and again with my ui.vision example i am able to execute the function on an element that isn’t actually currently visible on the webpage.

So my question is basically, can i call a function thats already on the webpage and simply provide the input?

@jlpath

you can select whole window in inject js and then use the function as below

function(e){
testJavascript('231231', '2','');;
}

cheers

1 Like

I was able to get this to execute, but for some reason it’s not fully functioning. I got an error that the function doesn’t exist. I’ll have to figure out another solution it seems. I appreciate the help!

1 Like

@jlpath

Mostly its looking for the event

Even in uipth you can use simulate or chromium api to send click to a element which is nit visisble

Also can do same from the inject js aslso…but clcik with simulate should solve the issue

Cheers

Okay, I found a fix. The issue was that I had to adjust the inject JS Script “Execution World” property to be Page, instead of leaving it blank (which I guess defaults to Isolated).

1 Like

@jlpath

Glad it worked

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.