Power Automate Desktop keyboard actions fail to interact with JavaScript functions on the server?

The title summarizes my hypothesis about the issue I’m facing. Here’s the situation:

I'm tasked with downloading a large number of files from an outdated system called Cogon. Unfortunately, the only viable method to retrieve the data is by manually clicking through the interface. This process involves navigating to a dialogue box, setting specific "from" and "to" dates to a single day, clicking "Ok," and then downloading the data.

When I execute this process manually, it works as expected. However, when attempting to automate the clicks with Power Automate Desktop, I can fill out the fields correctly in various ways. Yet, when I click "Ok," it seems as if no input was entered.

Is there anyone who can suggest what might be going wrong and how I could potentially resolve this issue?

The interface I'm interacting with is shown in the image below:

This is the code snippet for the input field regarding the "from" date:

The strategies I’ve attempted include:

  • Sending numeric values via keystrokes
  • Emulating keyboard inputs for numeric values
  • Utilizing only Up/Down navigational commands
  • Employing JavaScript to set the input field values

Here’s the JavaScript code used for setting values:

function RunScript() { document.querySelectorAll('input[id ^=VWG][id $=_1][class="Common-FontData DateTimePicker-InputValue_eq"]')[0].value=%Day%; document.querySelectorAll('input[id ^=VWG][id $=_3][class="Common-FontData DateTimePicker-InputValue_eq"]')[0].value=%Month%; document.querySelectorAll('input[id ^=VWG][id $=_5][class="Common-FontData DateTimePicker-InputValue_eq"]')[0].value=%Year%; document.querySelectorAll('input[id ^=VWG][id $=_1][class="Common-FontData DateTimePicker-InputValue_eq"]')[1].value=%Day%; document.querySelectorAll('input[id ^=VWG][id $=_3][class="Common-FontData DateTimePicker-InputValue_eq"]')[1].value=%Month%; document.querySelectorAll('input[id ^=VWG][id $=_5][class="Common-FontData DateTimePicker-InputValue_eq"]')[1].value=%Year%; }

The selector approach is necessary as the ID varies for each session. While visually the input appears to be set correctly, when I focus on the field and try to adjust the value using the down arrow key, it reverts to 24, regardless of the value set prior.

Could this issue stem from some underlying JavaScript functions that are crucial for backend communication, which I might not be triggering, even when simulating key presses?

Your situation with Power Automate Desktop not interacting as expected with the JavaScript functions in the backend of Cogon is intriguing and reflects a common challenge when automating older systems. You have taken a thorough approach by trying various input methods and using JavaScript to manipulate DOM elements. Let’s look at a potential troubleshooting approach and solution:

Understanding the Problem

From your description, it seems the JavaScript functions attached to the input elements are likely responsible for more than simply displaying data. These functions could be making AJAX calls or setting some backend values when certain events (like input changes) are triggered. By just changing the value via JavaScript, these event handlers might not be triggered, which can prevent the application from recognizing the new data.

Possible Solutions

Here are a few strategies you might consider that could help trigger the necessary JavaScript functions:

1. Trigger JavaScript Events Programmatically

After setting the values programmatically, you need to ensure that the associated events (e.g., onchange or onblur) are triggered. You can do this by manually dispatching the events in your script. Here is an example:

function triggerEvent(element, eventName) {
  var event = new Event(eventName, {
    bubbles: true,
    cancelable: true
  });
  element.dispatchEvent(event);
}

function RunScript() {
  var dayInput = document.querySelectorAll('input[id ^=VWG][id $=_1][class="Common-FontData DateTimePicker-InputValue_eq"]')[0];
  dayInput.value = %Day%;
  triggerEvent(dayInput, 'change');
  triggerEvent(dayInput, 'blur');

  // Repeat for other inputs and events as necessary
}

2. Use Native Automation Components

If the problem persists, consider exploring plugins or scripts that allow Power Automate Desktop to execute JavaScript directly in the browser. This way, you might be able to manipulate the Web API calls as needed.

3. Manual Invocation of JavaScript Functions

If the script still does not trigger the intended behavior, it might be necessary to analyze the existing JavaScript functions you mentioned like mobjApp.DateTimePicker_OnFocus, and call them directly after setting the values.

Debugging Tips

  • Developer Tools: Use the browser's Developer Tools to inspect any network requests or JavaScript errors when manually entering data, to understand what's being triggered behind the scenes.
  • Event Listeners: Check if there are any specific events that are fired upon interaction which might be causing the data to revert or not to be processed.
  • Console Logging: Add logging in the Developer Tools' console to verify the interactions when executing the script.

With these methods, you should be able to address the JavaScript handling issue in your automation script. Adapting the automation to handle such dynamic and enriched interactions often requires testing and incremental adjustments.