cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke Javascript Fragment and Invoke Javascript Function

Vikram.R
Level 4
Hi,

I am unable to click or perform action in web based application. Therefore I thought  of using invoke javascript fragment and invoke javascript function. I am not able to find proper documents  to work this can anyone guide me any documents
4 REPLIES 4

Hi Vikram,

Below as you see is the workflow for JS execution where I have created a custom business object to enter a search text on Google and click on the search button of Google.


35099.png

Going inside this business object now, you can see I have two data items created called, Insert JS Fragment and Invoke JS Fragment.

The Insert JS Fragment has a function definition mentioned which looks for an HTML element with the name attribute as "q" which is the search textbox in google and then writes the value which I am passing through it. Once the value has been written, the code looks for the name attribute as "btnK" which is the search button.

The function is as follows:

function writeText(searchText){
                    document.getElementsByName("q")[0].value = searchText;
                    document.getElementsByName("btnK")[0].click();
}

The Invoke JS Fragment is calling that function while passing the value as well which in my case is : writeText("Blue Prism")

Now in order to execute both these functions one by one I have used one Navigate Stage and have used the action "Insert Javascript Fragment" twice. The first time I am inserting the "Insert JS Fragment" data item and the next time I and again using the same action for inserting the "Invoke JS Fragment" data item.

35100.png
35101.png

In your case also the actions will be similar, the only thing that will change is the JavaScript code where you can use getElementById if you have the ID attribute for which you just need to use the click() function and not write anything. Also, no input parameter would be required to be sent out so your Invoke JS Fragment data item would also be something simple like: function_name()  which in my case was writeText("Blue Prism")


------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
WonderBotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

Neel1
MVP
hello @Vikram.R - Apart from all the really good information shared by @devneetmohanty07 .

I think Invoke and insert JS will no longer work when Manifest V3 will come so design your bot carefully.  ​​

Vikram.R
Level 4
Hi Devneet

Hope you are doing well,

The main issue was while performing click or press operation through blueprism the navigation stage is passing without performing the click action. So for this reason I thought of invoking java script. As Neeraj mentioned, invoking js no longer work after manifest V3, I would request you to suggest any other solution to resolve the issue.

Neel1
MVP
Hello  @Vikram.R,

Please can you share few details regarding your issue​.
Snapshot of application where you are not able to click?
What error you are getting ?
Have you tried UIA mode in case browser mode is not working?​
Which version of BP you are using?
Which browser you are using?