Issue with JavaScript Output in Execute Script

Hello @Allan_Zimmermann,

I’m currently working on a web automation project where I need to extract data from a portal. The element I want to interact with is inside the Shadow DOM, which makes capturing the selectors challenging. Therefore, I’m using JavaScript to extract the required data.

Here’s the JavaScript code I’m using:

(() => {
// Declare the sShowDetails variable
let sShowDetails = null;

try {
    // Locate the shadow host
    const shadowHost = document.querySelector("#main-wrapper > div.page-wrapper > div > div > mymsc-instantquote-app");
    if (shadowHost) {
        const shadowRoot = shadowHost.shadowRoot;
        if (shadowRoot) {
            // Locate the element inside the shadow DOM to retrieve the data from
            const dataElement = shadowRoot.querySelector("#root > div.breakdown-modal.f-Archivo.MuiModal-root.css-8ndowl > div.breakdown-modal-container");
            if (dataElement) {
                // Extract the text or inner HTML of the element
                const data = dataElement.innerText.trim() || dataElement.innerHTML.trim();

                // Create a JSON object with the data
                sShowDetails = { data };

                // Log the output in JSON format
                console.log("JSON Output:", JSON.stringify(sShowDetails, null, 2));

                // Write the output as a new line in the console (writeLine equivalent in web)
                const outputLine = document.createElement("div");
                outputLine.textContent = `Output Data: ${JSON.stringify(sShowDetails, null, 2)}`;
                document.body.appendChild(outputLine);
            } else {
                console.error("Element not found inside the shadow DOM.");
            }
        } else {
            console.error("Shadow root not found.");
        }
    } else {
        console.error("Shadow host not found.");
    }
} catch (error) {
    console.error("Error retrieving data:", error);
}

// Return sShowDetails
return sShowDetails;

})();

The output of the script is displayed correctly in the Chrome browser’s console, as shown below:

However, when I run the same script in OpenRPA’s Execute Script activity, the output is not shown in the Output Panel as seen in the screenshot below:


How can I get the output of this JavaScript script to appear in OpenRPA’s Output Panel? I’m looking for guidance on how to handle this situation, and if there are any OpenRPA-specific methods for logging output that would capture the result.

Any help would be appreciated!

Thanks,
Ashok S

what does the chrome console say, when you run it from openrpa ?

also, try returning the object as json, not an object.
The debugger DOES support objects, but if i remember correctly, the openrpa extension assumes the results is ether bool, number or string ( I’m not 100% here )

1 Like

Thank you for your response, @Allan_Zimmermann

I am using the “Execute Script” activity to extract data from the portal and store it in variable1 then assign variable1 to variable2 so that I can access variable2 outside the activity. How can I retrieve the output from variable2 in “Execute Script”?

Is the “Execute Script” activity only intended for actions like “Type Into” or “Click”? Or can it also be used to assign values to variables and retrieve the output, or even write to a Notepad file?