cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to Invoke Inserted JavaScript Fragment

Anonymous
Not applicable
Hi, I am attempting to insert a Javascript fragment into a webpage and then invoke it using blue prism. The purpose of this is to analyse what elements are returned from a search to determine where to go next in the overall process flow. I have tested the Javascript code on the intended website using the IE 11 developer console and it works without issue. The code is below in case it is useful. function includes(stringToCheck, CharacterToSearchFor) {     var found = new Boolean();     var splitString = stringToCheck.split("");     for (var index = 0; index < splitString.length; index++)     {         if(splitString[index] == CharacterToSearchFor)         {             return true;         }     }     return false; } function getPartners() //declare a function which can be called from BP. once called all code within the enclosing {} will be run {     var searchResults = document.getElementsByClassName("findASolicitorListItem"); //search the web page for all elements with a specific tag and store them in a variable called searchResults.     if(searchResults.length == 0) // If the number     {         alert( "No Solicitors were found.");     }else if(searchResults.length == 1)     {         var innerSearchResults = searchResults[0].getElementsByTagName("span");         for(i = 0; i < innerSearchResults.length; i++)         {             var spanText = innerSearchResults.innerText.toString();             if((spanText != ""))             {                 if(!includes(spanText, "|"))                 {                     alert("One Solicitor found. " + spanText);                 }             }         }     }else if (searchResults.length > 1)     {         alert( "More than one solicitor was found. Manual Checking required.");     } } This is stored in a data item and is passed into the Navigate stage (Insert Javascript Fragment) parameter. PrintScreen of Insert Javascript Fragment stage When this stage is ran it successfully injects the Javascript functions into the webpage. I then try and invoke this inserted javascript fragment Printscreen of Invoke Javascript Function stage When this stage runs I get the following error message raised by Blue Prism. Internal : Failed to perform step 1 in Navigate Stage 'Analyse Result' on page 'Analyse Search Results' - Failed while invoking javascript method:Exception from HRESULT: 0x80020101-> at mshtml.HTMLWindow2Class.IHTMLWindow2_execScript(String code, String language) at BluePrism.ApplicationManager.HTML.clsHTMLDocument.InvokeJavascriptMethod(String methodname, String jsonargs, Object& retval, String& sErr) I have searched for this error code and found this answer which indicates there is a problem with the code however I can manually run this code just fine. Does anyone have any experience with using these methods in BluePrism or have seen this error message before who can help me resolve?
2 REPLIES 2

PawełMiżwa
Level 3
Hi, I have used @Atem.Ratkevich solution, but it result in during invoke internal error: Internal : Failed To perform Step 1 In Navigate Stage 'Invoke' on page 'Action 1' - Failed while invoking javascript method:Exception from HRESULT: 0x80020101->   at MSHTML.IHTMLWindow2.execScript(String code, String language) at BluePrism.ApplicationManager.HTML.clsHTMLDocument.InvokeJavascriptMethod(String methodname, String jsonargs, Object& retval, String& sErr) Entire BP script is the same, page interact with js - console work. Someone could assist ? Regards, Pawel  

Hi, 
the best way that i found is to Create a Data Item type text and when inserting the initial value select Javascript mode, then create navigate stage to insert the javascript fragment using the dataitem (better with a function like function JsFunction(){alert"hi"}) and then invoke js function in the second step of navigate stage calling the function  "JsFunction" and arguments "[{}]"
Hope this helps
Regards 
Roberto

------------------------------
Roberto Bagnato
------------------------------