Skip to main content

How to capture ajax responses using the Capture Ajax Responses (Regex) URL/Link Action Property.

The Capture Ajax Responses (Regex) URL/Link Action property enables users to directly capture the AJAX responses. This property simplifies the process of capturing specific data from AJAX responses by utilizing regular expressions (Regex).

A regular expression matching URLs for which the Ajax responses are available should be added in the Capture Ajax Responses (Regex) URL/Link Action property which makes the JSON response data available for capturing and loading the responses using the JSON parser. Multiple regular expressions separated by line breaks can be specified.

When we load any URL on a dynamic browser it loads many other requests and their responses along with the original URL request. For example, when we load the web page https://training.sequentum.com/json it also loads multiple Ajax requests and their responses which you can easily see on the Web Browser Activity window as highlighted in the screenshot below:

In the above example, If you want to capture the highlighted Ajax Content you can just open the Web Request Editor by simply double-clicking on the corresponding Activity column and you will be able to open the Web Request Editor window as shown in the screenshot below:

 

 

Now, in order to capture the Ajax response for the above URL we can use the request URL to generate our Regex pattern and then we can set the same in the Capture Ajax Responses (Regex) URL/Link Action property to capture all the responses.

 

We can set the following string in the Regex Box to get all the similar requests while loading the URL on the Dynamic browser and then we can use the args.HtmlDocument.AjaxResponses["string key"] method to filter out the specific Ajax response data that we want to capture.

https://training.sequentum.com/json.*

Using the AjaxResponses

You can use the AjaxResponses SE internal C# scripting method by using the following code

CODE
 args.HtmlDocument.AjaxResponses["string key"];

There could be more than one Ajax response captured through the regex used in the URL/Link Action property while loading the URL on the dynamic browser. We can filter out the responses using the string key "1" or  "2" or "3" which will represent the key number in the list of the captured responses.  

In the above example when we use the above code in a Calculated Value command to get the captured response, we will get the following JSON data which will be similar to what is shown in the Ajax Content column of the Web Request Editor window:

CODE
{"product_data": [{"ProductName": "Russell Brake Bleeder Screw 639590","PartNumber": "639590","Category": "Brake Bleeder Screw","Qty": "51"},{"ProductName": "Russell Brake Bleeder Screw 639520","PartNumber": "639520","Category": "Brake Bleeder Screw","Qty": "56"},{"ProductName": "Russell Brake Bleeder Screw 639600","PartNumber": "639600","Category": "Brake Bleeder Screw","Qty": "78"},{"ProductName": "Russell Brake Bleeder Screw 639580","PartNumber": "639580","Category": "Brake Bleeder Screw","Qty": "13"},{"ProductName": "Russell Brake Bleeder Screw 639570","PartNumber": "639570","Category": "Brake Bleeder Screw","Qty": "23"},{"ProductName": "Russell Brake Bleeder Screw 639530","PartNumber": "639530","Category": "Brake Bleeder Screw","Qty": "39"},{"ProductName": "Russell Brake Bleeder Screw 639630","PartNumber": "639630","Category": "Brake Bleeder Screw","Qty": "67"},{"ProductName": "Russell Brake Bleeder Screw 639610","PartNumber": "639610","Category": "Brake Bleeder Screw","Qty": "64"},{"ProductName": "Russell Brake Bleeder Screw 639540","PartNumber": "639540","Category": "Brake Bleeder Screw","Qty": "59"},{"ProductName": "Russell Brake Bleeder Screw 639560","PartNumber": "639560","Category": "Brake Bleeder Screw","Qty": "3"},{"ProductName": "Russell Brake Bleeder Screw 639550","PartNumber": "639550","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Russell Brake Bleeder Screw 639510","PartNumber": "639510","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Russell Brake Bleeder Screw 639620","PartNumber": "639620","Category": "Brake Bleeder Screw","Qty": "40"},{"ProductName": "Dorman Brake Bleeder Screw 13901","PartNumber": "13901","Category": "Brake Bleeder Screw","Qty": "77"},{"ProductName": "Dorman Brake Bleeder Screw 13905","PartNumber": "13905","Category": "Brake Bleeder Screw","Qty": "21"},{"ProductName": "Dorman Brake Bleeder Screw 484-152","PartNumber": "484-152","Category": "Brake Bleeder Screw","Qty": "4"},{"ProductName": "Dorman Brake Bleeder Screw 12702","PartNumber": "12702","Category": "Brake Bleeder Screw","Qty": "15"},{"ProductName": "Dorman Brake Bleeder Screw 13908","PartNumber": "13908","Category": "Brake Bleeder Screw","Qty": "34"},{"ProductName": "Dorman Brake Bleeder Screw 13949","PartNumber": "13949","Category": "Brake Bleeder Screw","Qty": "51"},{"ProductName": "Dorman Brake Bleeder Screw 12708","PartNumber": "12708","Category": "Brake Bleeder Screw","Qty": "78"},{"ProductName": "Dorman Brake Bleeder Screw 13906","PartNumber": "13906","Category": "Brake Bleeder Screw","Qty": "40"},{"ProductName": "Dorman Brake Bleeder Screw 12706","PartNumber": "12706","Category": "Brake Bleeder Screw","Qty": "9"},{"ProductName": "Dorman Brake Bleeder Screw 12705","PartNumber": "12705","Category": "Brake Bleeder Screw","Qty": "97"},{"ProductName": "Dorman Brake Bleeder Screw 12701","PartNumber": "12701","Category": "Brake Bleeder Screw","Qty": "76"},{"ProductName": "Dorman Brake Bleeder Screw 484-150.1","PartNumber": "484-150.1","Category": "Brake Bleeder Screw","Qty": "24"},{"ProductName": "Dorman Brake Bleeder Screw 13902","PartNumber": "13902","Category": "Brake Bleeder Screw","Qty": "24"},{"ProductName": "Dorman Brake Bleeder Screw 484-152.1","PartNumber": "484-152.1","Category": "Brake Bleeder Screw","Qty": "21"},{"ProductName": "Dorman Brake Bleeder Screw 484-151.1","PartNumber": "484-151.1","Category": "Brake Bleeder Screw","Qty": "85"},{"ProductName": "Dorman Brake Bleeder Screw 12703","PartNumber": "12703","Category": "Brake Bleeder Screw","Qty": "4"},{"ProductName": "Dorman Brake Bleeder Screw 12709","PartNumber": "12709","Category": "Brake Bleeder Screw","Qty": "77"},{"ProductName": "Dorman Brake Bleeder Screw 13909","PartNumber": "13909","Category": "Brake Bleeder Screw","Qty": "35"},{"ProductName": "Dorman Brake Bleeder Screw 12704","PartNumber": "12704","Category": "Brake Bleeder Screw","Qty": "99"},{"ProductName": "Dorman Brake Bleeder Screw 13904","PartNumber": "13904","Category": "Brake Bleeder Screw","Qty": "94"},{"ProductName": "Dorman Brake Bleeder Screw 12707","PartNumber": "12707","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Dorman Brake Bleeder Screw 13903","PartNumber": "13903","Category": "Brake Bleeder Screw","Qty": "75"},{"ProductName": "Duralast Brake Bleeder Screw H9427","PartNumber": "H9427","Category": "Brake Bleeder Screw","Qty": "53"},{"ProductName": "Duralast Brake Bleeder Screw H9494-2","PartNumber": "H9494-2","Category": "Brake Bleeder Screw","Qty": "16"},{"ProductName": "ACDelco Brake Bleeder Screw 179-1098","PartNumber": "179-1098","Category": "Brake Bleeder Screw","Qty": "17"},{"ProductName": "ACDelco Brake Bleeder Screw 25846360","PartNumber": "25846360","Category": "Brake Bleeder Screw","Qty": "98"},{"ProductName": "ACDelco Brake Bleeder Screw 88967108","PartNumber": "88967108","Category": "Brake Bleeder Screw","Qty": "17"},{"ProductName": "ACDelco Brake Bleeder Screw 25900782","PartNumber": "25900782","Category": "Brake Bleeder Screw","Qty": "22"},{"ProductName": "Earl's Plumbing Brake Bleeder Screw 280025ERL","PartNumber": "280025ERL","Category": "Brake Bleeder Screw","Qty": "22"}]}

Further, we can easily load the captured JSON data by simply adding the json:// URL with the captured json data which will allow us to load the data in a JSON parser in the Navigation command.

CODE
json://{"product_data": [{"ProductName": "Russell Brake Bleeder Screw 639590","PartNumber": "639590","Category": "Brake Bleeder Screw","Qty": "51"},{"ProductName": "Russell Brake Bleeder Screw 639520","PartNumber": "639520","Category": "Brake Bleeder Screw","Qty": "56"},{"ProductName": "Russell Brake Bleeder Screw 639600","PartNumber": "639600","Category": "Brake Bleeder Screw","Qty": "78"},{"ProductName": "Russell Brake Bleeder Screw 639580","PartNumber": "639580","Category": "Brake Bleeder Screw","Qty": "13"},{"ProductName": "Russell Brake Bleeder Screw 639570","PartNumber": "639570","Category": "Brake Bleeder Screw","Qty": "23"},{"ProductName": "Russell Brake Bleeder Screw 639530","PartNumber": "639530","Category": "Brake Bleeder Screw","Qty": "39"},{"ProductName": "Russell Brake Bleeder Screw 639630","PartNumber": "639630","Category": "Brake Bleeder Screw","Qty": "67"},{"ProductName": "Russell Brake Bleeder Screw 639610","PartNumber": "639610","Category": "Brake Bleeder Screw","Qty": "64"},{"ProductName": "Russell Brake Bleeder Screw 639540","PartNumber": "639540","Category": "Brake Bleeder Screw","Qty": "59"},{"ProductName": "Russell Brake Bleeder Screw 639560","PartNumber": "639560","Category": "Brake Bleeder Screw","Qty": "3"},{"ProductName": "Russell Brake Bleeder Screw 639550","PartNumber": "639550","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Russell Brake Bleeder Screw 639510","PartNumber": "639510","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Russell Brake Bleeder Screw 639620","PartNumber": "639620","Category": "Brake Bleeder Screw","Qty": "40"},{"ProductName": "Dorman Brake Bleeder Screw 13901","PartNumber": "13901","Category": "Brake Bleeder Screw","Qty": "77"},{"ProductName": "Dorman Brake Bleeder Screw 13905","PartNumber": "13905","Category": "Brake Bleeder Screw","Qty": "21"},{"ProductName": "Dorman Brake Bleeder Screw 484-152","PartNumber": "484-152","Category": "Brake Bleeder Screw","Qty": "4"},{"ProductName": "Dorman Brake Bleeder Screw 12702","PartNumber": "12702","Category": "Brake Bleeder Screw","Qty": "15"},{"ProductName": "Dorman Brake Bleeder Screw 13908","PartNumber": "13908","Category": "Brake Bleeder Screw","Qty": "34"},{"ProductName": "Dorman Brake Bleeder Screw 13949","PartNumber": "13949","Category": "Brake Bleeder Screw","Qty": "51"},{"ProductName": "Dorman Brake Bleeder Screw 12708","PartNumber": "12708","Category": "Brake Bleeder Screw","Qty": "78"},{"ProductName": "Dorman Brake Bleeder Screw 13906","PartNumber": "13906","Category": "Brake Bleeder Screw","Qty": "40"},{"ProductName": "Dorman Brake Bleeder Screw 12706","PartNumber": "12706","Category": "Brake Bleeder Screw","Qty": "9"},{"ProductName": "Dorman Brake Bleeder Screw 12705","PartNumber": "12705","Category": "Brake Bleeder Screw","Qty": "97"},{"ProductName": "Dorman Brake Bleeder Screw 12701","PartNumber": "12701","Category": "Brake Bleeder Screw","Qty": "76"},{"ProductName": "Dorman Brake Bleeder Screw 484-150.1","PartNumber": "484-150.1","Category": "Brake Bleeder Screw","Qty": "24"},{"ProductName": "Dorman Brake Bleeder Screw 13902","PartNumber": "13902","Category": "Brake Bleeder Screw","Qty": "24"},{"ProductName": "Dorman Brake Bleeder Screw 484-152.1","PartNumber": "484-152.1","Category": "Brake Bleeder Screw","Qty": "21"},{"ProductName": "Dorman Brake Bleeder Screw 484-151.1","PartNumber": "484-151.1","Category": "Brake Bleeder Screw","Qty": "85"},{"ProductName": "Dorman Brake Bleeder Screw 12703","PartNumber": "12703","Category": "Brake Bleeder Screw","Qty": "4"},{"ProductName": "Dorman Brake Bleeder Screw 12709","PartNumber": "12709","Category": "Brake Bleeder Screw","Qty": "77"},{"ProductName": "Dorman Brake Bleeder Screw 13909","PartNumber": "13909","Category": "Brake Bleeder Screw","Qty": "35"},{"ProductName": "Dorman Brake Bleeder Screw 12704","PartNumber": "12704","Category": "Brake Bleeder Screw","Qty": "99"},{"ProductName": "Dorman Brake Bleeder Screw 13904","PartNumber": "13904","Category": "Brake Bleeder Screw","Qty": "94"},{"ProductName": "Dorman Brake Bleeder Screw 12707","PartNumber": "12707","Category": "Brake Bleeder Screw","Qty": "61"},{"ProductName": "Dorman Brake Bleeder Screw 13903","PartNumber": "13903","Category": "Brake Bleeder Screw","Qty": "75"},{"ProductName": "Duralast Brake Bleeder Screw H9427","PartNumber": "H9427","Category": "Brake Bleeder Screw","Qty": "53"},{"ProductName": "Duralast Brake Bleeder Screw H9494-2","PartNumber": "H9494-2","Category": "Brake Bleeder Screw","Qty": "16"},{"ProductName": "ACDelco Brake Bleeder Screw 179-1098","PartNumber": "179-1098","Category": "Brake Bleeder Screw","Qty": "17"},{"ProductName": "ACDelco Brake Bleeder Screw 25846360","PartNumber": "25846360","Category": "Brake Bleeder Screw","Qty": "98"},{"ProductName": "ACDelco Brake Bleeder Screw 88967108","PartNumber": "88967108","Category": "Brake Bleeder Screw","Qty": "17"},{"ProductName": "ACDelco Brake Bleeder Screw 25900782","PartNumber": "25900782","Category": "Brake Bleeder Screw","Qty": "22"},{"ProductName": "Earl's Plumbing Brake Bleeder Screw 280025ERL","PartNumber": "280025ERL","Category": "Brake Bleeder Screw","Qty": "22"}]}

 

 

A sample agent demonstrating the above feature is attached herewith.

CaptureAjaxResponses.scgx

CaptureAjaxResponses.scgx

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.