I am clicking a button on a web page that calls an API and generated the response below. Is there a way to get the response value programmatically without having UiPath open the console?
I know there is a way to call the API, but the website is not mine, so I am unsure what variables to pass.
I created a sample local HTML file (LocalHTMLPage.html) that performs a RestAPI call in the backend when you press the Search Users button.
It uses two Inject Js Script activities:
Inject Js Script - Verify if you can detect ANY network activity
Inject Js Script - Get the API data
Before the Inject Js Script - Get the API data perform the UI element action that will trigger the Rest API call. Use delays between actions so it will get a successful loaded Rest API call with results.
Try the steps exactly as follows: Use an empty string "" as the Input parameter, and set Execution World = Page so the script runs in the actual page context. Then inject the following JS without quotes to intercept the API call:
(function () {
const open = XMLHttpRequest.prototype.open;
const send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function (method, url) {
this._url = url;
open.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function (body) {
this.addEventListener('load', function () {
if (this._url.includes('YOUR_API_KEYWORD')) {
window.lastApiResponse = this.responseText;
}
});
send.apply(this, arguments);
};
})();
After triggering the action that makes the API call, run a second Inject JS Script (again with Input = "") containing:
@Dan_Munteanu
From my tries, the Application Event Trigger for click doesnât work for default selector and UI default framework, as it expects an app selector from Active Accessibility.
Invalid Trigger. Only 'app' attribute is allowed for 'html' selector. Exception Type: UiPath.UIAutomationNext.Exceptions.UiAutomationException in .local\generated\Triggers.Generated.xaml at NNativeEventTrigger`1 "Application Event Trigger 'Search Users'" at TriggerScope "TriggerScope" at Sequence "Sequence" at Sequence "Sequence" at Triggers_Generated "Triggers.Generated" UiPath.UIAutomationNext.Exceptions.UiAutomationException: Invalid Trigger. Only 'app' attribute is allowed for 'html' selector. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80040329 at UiPath.UiNodeMonitorClass.MonitorNativeEvent(String bstrSelector, String nativeEvent, Boolean isCollapsable, Boolean matchSync, Boolean matchChildren, Boolean searchInvisibleChildren, String bstrServerUrlForBrowserEvents) at UiPath.UIAutomationNext.Triggers.EventMonitor.<>c__DisplayClass23_0.<RegisterNativeEventInternal>b__0() at UiPath.UIAutomationNext.Services.DriverServiceCore.WrapCom[T](Func`1 toExecute) --- End of inner exception stack trace --- at UiPath.UIAutomationNext.Extensions.ExceptionExtensions.GetFriendly(COMException comException) at UiPath.UIAutomationNext.Extensions.ExceptionExtensions.ThrowFriendly(COMException comException) at UiPath.UIAutomationNext.Services.DriverServiceCore.WrapCom[T](Func`1 toExecute) at UiPath.UIAutomationNext.Triggers.EventMonitor.RegisterNativeEventInternal(SelectorTriggerNativeEventData triggerData, Boolean saveMonitorId) at UiPath.UIAutomationNext.Triggers.EventMonitor.<RegisterNativeEvent>b__19_0(SelectorTriggerNativeEventData t) at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList() at UiPath.UIAutomationNext.Triggers.EventMonitor.RegisterNativeEvent(IEnumerable`1 triggerData) at UiPath.UIAutomationNext.Services.EventMonitorFactory.Create(IEnumerable`1 triggerData) at UiPath.UIAutomationNext.Activities.NNativeEventTrigger`1.CreateMonitor(NativeActivityContext context, IEventMonitorFactory factory, IRuntimeContext runtimeContext, Action`1 sendTrigger) at UiPath.UIAutomationNext.Activities.TriggerBase`1.StartMonitor(NativeActivityContext context, Action`1 sendTrigger) at UiPath.Platform.Triggers.TriggerBase`1.Execute(NativeActivityContext context) at UiPath.Platform.Triggers.InterruptibleTriggerBase`1.ExecuteAsInterruptibleTrigger(NativeActivityContext context) at UiPath.Platform.Triggers.InterruptibleTriggerBase`1.Execute(NativeActivityContext context) at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Can you provide an updated version of the ApplicationEventTriggerSequence.xaml that works as expected for the provided sample?
InterceptRestAPIWithInjectJsScriptActivity.zip (6.1 MB) @marian.platonov Thanks for trying it.
This exception is expected: âInvalid Trigger. Only âappâ attribute is allowed for âhtmlâ selector.â It canât be the default one because for most tab (html) level events, we have to monitor all tabs, and details about the tab that triggered the event should be visible in the TriggerEventArgs.
In your case, use a simple selector <html app='chrome.exe' />
I attached a workflow that works with UiAutomation 24.10.14.
Each trigger is in its own workflow and the main.xaml calls âRun Local Triggersâ activity to start them all.
I first tried using 25.10.22, but I couldnât get past UI issues that Iâm going to share with the team.