Inject JS Script: Trying to insert jquery but failing to do so

I’m trying to extracted some complex html table with the combination of jquery using $ and common java script commands but i’m ended up with error _clientFunc is not a function

Below is the javascript I’m trying to write

function ExtractTable() {

var script=document.createElement(“script”);

script.src=“//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”;

script.onload=function() {

var table=$(‘[grid_ref_page=“TempRegionList.pxResults(1)”]’)[0];

var rows=table.getElementsByTagName(“tr”);

var JurisdictionValue=rows[2].querySelector(‘td[data-attribute-name=Jurisdiction’).innerText

};

JurisdictionValue.appendChild(script);

return JurisdictionValue;

}();
Please help

Hi @Soumya_P,

The first red flag I see are double quotes. The Inject Javascript activity will not accept double quotes in your function. Thankfully, JavaScript like PowerShell allows use of single quote on string values. So could you try the below code. I have made some changes to your code.

function ExtractTable() {
var script=document.createElement('script');
script.src='//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js';
script.onload=function() {
var table=$('[grid_ref_page='TempRegionList.pxResults(1)']')[0];
var rows=table.getElementsByTagName('tr');
var JurisdictionValue=rows[2].querySelector('td[data-attribute-name]=Jurisdiction').innerText
};
JurisdictionValue.appendChild(script);
return JurisdictionValue;
}();
  • You were also missing a “]” in var JurisdictionValue=rows[2].querySelector('td[data-attribute-name=Jurisdiction').innerText

  • Another thing I am uncertain of is how Inject JavaScript handles your return value (JurisdictionValue). The return value will need to be cast to a datatable since you are trying to scrape a “td”

I cannot test it as I have no idea which website you are trying this on.

I’m really not able to execute even after correcting the changes, can u suggest me how can we execute jquery in uipath

~WRD000.jpg

Hi @Soumya_P ,

If you would like to execute jQuery in UiPath, I coded a custom activity below to make it possible.
jQuery Execution Activities
https://marketplace.uipath.com/listings/jquery-execution-activities1018

You can download it from the link above, or alternatively, search “jqueryexecution” in your UiPath Studio’s Manage Packages window.
Please have a look at the user guide document for details if needed.
Hope you find this helpful.
Thanks.

1 Like