Level Up Your Automation: XPath & JSONPath Explained (With Macro Scheduler Examples)

Published on February 1, 2026 by Marcus Tettmar in Scripting, Web/Tech

If you automate websites, APIs, or online services with Macro Scheduler, you’ll quickly run into two recurring challenges:

  • Finding the right element on a web page
  • Extracting the right value from structured JSON data

Two technologies solve these problems:

  • XPath — for navigating and selecting HTML elements
  • JSONPath — for querying and extracting values from JSON

We’ve published two practical primer articles that go deep into both topics:

👉 An XPath Primer for Web Automation (with Macro Scheduler examples)
https://help.mjtnet.com/article/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples

👉 A JSONPath Primer (with Macro Scheduler examples)
https://help.mjtnet.com/article/555-a-jsonpath-primer-with-macro-scheduler-examples

Below is a high-level overview of each, with real Macro Scheduler examples to show why these skills are so valuable.


🔹 XPath — Find Web Elements Reliably

https://help.mjtnet.com/article/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples

When automating Chrome using Macro Scheduler’s Chrome functions, element IDs and class names are often unreliable:

  • IDs may be missing or dynamically generated
  • Class names may change between builds
  • Multiple elements may share the same attributes

XPath lets you locate elements by describing their position and relationship within the page structure.

In Macro Scheduler, XPath is used with:

ChromeFindElements>session_id,xpath,value,elements_array

Example: Find an Input by Attribute

ChromeFindElements>session_id,xpath,//input[@name='q'],elements
ChromeSetElementValue>session_id,elements_1,macro scheduler

This finds an <input> element whose name attribute equals q.


Using Partial Matches

When values are dynamic:

ChromeFindElements>session_id,xpath,//button[contains(@id,'save')],elements

This matches any button whose ID contains the word “save”.


Real-World Scenario: Clicking a Button Based on a Child Element

HTML:

<button>
  <label for="checkbox-123">Pacific Islander</label>
  <input id="checkbox-123">
</button>

You know the ID of the input, but need to click the surrounding button.

XPath:

ChromeFindElements>session_id,xpath,//input[@id='checkbox-123']/ancestor::button,btn
ChromeClickElement>session_id,btn_1

This moves up the DOM from the input to its parent button.


Real-World Scenario: Find a Button Based on Nearby Text

HTML:

<div class="option">
  <h3>Premium Plan</h3>
  <button>Select</button>
</div>

XPath:

ChromeFindElements>session_id,xpath,//h3[text()='Premium Plan']/following-sibling::button,btn
ChromeClickElement>session_id,btn_1

This selects the button associated with the “Premium Plan” heading.


XPath Best Practices

  • Prefer relative paths starting with //
  • Use contains() for dynamic values
  • Avoid full /html/body/... absolute paths
  • Check elements_array_count before using results

For a full walkthrough and many more patterns, see:
https://help.mjtnet.com/article/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples


🔹 JSONPath — Extract Data from JSON

https://help.mjtnet.com/article/555-a-jsonpath-primer-with-macro-scheduler-examples

JSON is everywhere: APIs, cloud services, configuration files, and web responses.

Macro Scheduler’s JSONParse command uses JSONPath to pull specific values from JSON text.

JSONParse>json_string,json_path,result_array

Results are always returned as an array:

  • result_array_1
  • result_array_2
  • result_array_count

Example: Extract a Simple Value

JSON:

{ "uid": "1234" }

Macro Scheduler:

JSONParse>sJSON,$.uid,result
MessageModal>UID is: %result_1%

Note the required $ at the start of the path.


Working with Arrays

JSONParse>sJSON,$.clients[0],result

Gets the first client.

JSONParse>sJSON,$.clients[*],result

Gets all clients.


Using Filters

Select only books cheaper than 10:

JSONParse>json,$.store.book[[email protected] < 10],cheapBooks

Select books that contain an ISBN:

JSONParse>json,$.store.book[[email protected]],withIsbn

Get titles of books under 15:

JSONParse>json,$.store.book[[email protected] < 15].title,titles

JSONPath Best Practices

  • Always start paths with $
  • Remember results are arrays
  • Check result_count before using values
  • Build paths step by step

For full explanations and more examples:
https://help.mjtnet.com/article/555-a-jsonpath-primer-with-macro-scheduler-examples


Final Thoughts

XPath and JSONPath solve two of the most common automation problems:

  • XPath → finding the right element on a web page
  • JSONPath → extracting the right value from structured data

Mastering these will make your Macro Scheduler scripts more reliable, more flexible, and easier to maintain.

If you regularly automate websites or APIs, these two primers are essential reading.