Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in RPA by (12.8k points)

I am attempting to insert a Javascript fragment into a webpage and then invoke it using blue prism. The purpose of this is to analyze 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[i].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.

it successfully injects the Javascript functions into the webpage. I then try and invoke this inserted javascript fragment

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?

1 Answer

0 votes
by (29.8k points)

To invoke the function by action "Invoke Javascript function", in the Arguments field you should put arguments in JSON syntax. If there is no argument you put "[{}]".

or

use Insert Fragment for everything, invoking included.
If you insert this function as a fragment...

function sayHello(name)
{
    alert("Hello " + name + "!");
}

...to invoke it you just insert this as another fragment:

sayHello("World");

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 6, 2019 in RPA by Abhishek_31 (12.8k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...