{"id":3268,"date":"2026-02-01T16:38:10","date_gmt":"2026-02-01T16:38:10","guid":{"rendered":"https:\/\/www.mjtnet.com\/blog\/?p=3268"},"modified":"2026-02-02T09:00:33","modified_gmt":"2026-02-02T09:00:33","slug":"level-up-your-automation-xpath-jsonpath-explained-with-macro-scheduler-examples","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2026\/02\/01\/level-up-your-automation-xpath-jsonpath-explained-with-macro-scheduler-examples\/","title":{"rendered":"Level Up Your Automation: XPath &#038; JSONPath Explained (With Macro Scheduler Examples)"},"content":{"rendered":"\n<p>If you automate websites, APIs, or online services with Macro Scheduler, you\u2019ll quickly run into two recurring challenges:<\/p>\n\n\n\n<ul>\n<li>Finding the&nbsp;<strong>right element<\/strong>&nbsp;on a web page<\/li>\n\n\n\n<li>Extracting the&nbsp;<strong>right value<\/strong>&nbsp;from structured JSON data<\/li>\n<\/ul>\n\n\n\n<p>Two technologies solve these problems:<\/p>\n\n\n\n<ul>\n<li><strong>XPath<\/strong>&nbsp;\u2014 for navigating and selecting HTML elements<\/li>\n\n\n\n<li><strong>JSONPath<\/strong>&nbsp;\u2014 for querying and extracting values from JSON<\/li>\n<\/ul>\n\n\n\n<p>We\u2019ve published two practical primer articles that go deep into both topics:<\/p>\n\n\n\n<p>&#x1f449;&nbsp;<strong>An XPath Primer for Web Automation (with Macro Scheduler examples)<\/strong><br><a href=\"https:\/\/help.mjtnet.com\/article\/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples?utm_source=chatgpt.com\">https:\/\/help.mjtnet.com\/article\/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples<\/a><\/p>\n\n\n\n<p>&#x1f449;&nbsp;<strong>A JSONPath Primer (with Macro Scheduler examples)<\/strong><br><a href=\"https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples?utm_source=chatgpt.com\">https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples<\/a><\/p>\n\n\n\n<p>Below is a high-level overview of each, with real Macro Scheduler examples to show why these skills are so valuable.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2>&#x1f539; XPath \u2014 Find Web Elements Reliably<\/h2>\n\n\n\n<p><a href=\"https:\/\/help.mjtnet.com\/article\/554-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><\/p>\n\n\n\n<p>When automating Chrome using Macro Scheduler\u2019s Chrome functions, element IDs and class names are often unreliable:<\/p>\n\n\n\n<ul>\n<li>IDs may be missing or dynamically generated<\/li>\n\n\n\n<li>Class names may change between builds<\/li>\n\n\n\n<li>Multiple elements may share the same attributes<\/li>\n<\/ul>\n\n\n\n<p>XPath lets you locate elements by describing their&nbsp;<strong>position and relationship<\/strong>&nbsp;within the page structure.<\/p>\n\n\n\n<p>In Macro Scheduler, XPath is used with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ChromeFindElements&gt;session_id,xpath,value,elements_array<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Example: Find an Input by Attribute<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>ChromeFindElements&gt;session_id,xpath,\/\/input&#91;@name='q'],elements\nChromeSetElementValue&gt;session_id,elements_1,macro scheduler<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>This finds an&nbsp;<code>&lt;input&gt;<\/code>&nbsp;element whose&nbsp;<code>name<\/code>&nbsp;attribute equals&nbsp;<code>q<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Using Partial Matches<\/h3>\n\n\n\n<p>When values are dynamic:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ChromeFindElements&gt;session_id,xpath,\/\/button&#91;contains(@id,'save')],elements<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>This matches any button whose ID contains the word \u201csave\u201d.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Real-World Scenario: Clicking a Button Based on a Child Element<\/h3>\n\n\n\n<p>HTML:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;button&gt;\n  &lt;label for=\"checkbox-123\"&gt;Pacific Islander&lt;\/label&gt;\n  &lt;input id=\"checkbox-123\"&gt;\n&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>You know the ID of the&nbsp;<code>input<\/code>, but need to click the surrounding&nbsp;<code>button<\/code>.<\/p>\n\n\n\n<p>XPath:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ChromeFindElements&gt;session_id,xpath,\/\/input&#91;@id='checkbox-123']\/ancestor::button,btn\nChromeClickElement&gt;session_id,btn_1<\/code><\/pre>\n\n\n\n<p>This moves up the DOM from the input to its parent button.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Real-World Scenario: Find a Button Based on Nearby Text<\/h3>\n\n\n\n<p>HTML:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"option\"&gt;\n  &lt;h3&gt;Premium Plan&lt;\/h3&gt;\n  &lt;button&gt;Select&lt;\/button&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>XPath:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ChromeFindElements&gt;session_id,xpath,\/\/h3&#91;text()='Premium Plan']\/following-sibling::button,btn\nChromeClickElement&gt;session_id,btn_1<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>This selects the button associated with the \u201cPremium Plan\u201d heading.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>XPath Best Practices<\/h3>\n\n\n\n<ul>\n<li>Prefer relative paths starting with&nbsp;<code>\/\/<\/code><\/li>\n\n\n\n<li>Use&nbsp;<code>contains()<\/code>&nbsp;for dynamic values<\/li>\n\n\n\n<li>Avoid full&nbsp;<code>\/html\/body\/...<\/code>&nbsp;absolute paths<\/li>\n\n\n\n<li>Check&nbsp;<code>elements_array_count<\/code>&nbsp;before using results<\/li>\n<\/ul>\n\n\n\n<p>For a full walkthrough and many more patterns, see:<br><a href=\"https:\/\/help.mjtnet.com\/article\/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples?utm_source=chatgpt.com\">https:\/\/help.mjtnet.com\/article\/554-an-xpath-primer-for-web-automation-with-macro-scheduler-examples<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2>&#x1f539; JSONPath \u2014 Extract Data from JSON<\/h2>\n\n\n\n<p><a href=\"https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples\">https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples<\/a><\/p>\n\n\n\n<p>JSON is everywhere: APIs, cloud services, configuration files, and web responses.<\/p>\n\n\n\n<p>Macro Scheduler\u2019s&nbsp;<code>JSONParse<\/code>&nbsp;command uses JSONPath to pull specific values from JSON text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;json_string,json_path,result_array<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Results are always returned as an array:<\/p>\n\n\n\n<ul>\n<li><code>result_array_1<\/code><\/li>\n\n\n\n<li><code>result_array_2<\/code><\/li>\n\n\n\n<li><code>result_array_count<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Example: Extract a Simple Value<\/h3>\n\n\n\n<p>JSON:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{ \"uid\": \"1234\" }<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Macro Scheduler:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;sJSON,$.uid,result\nMessageModal&gt;UID is: %result_1%<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Note the required&nbsp;<code>$<\/code>&nbsp;at the start of the path.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Working with Arrays<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;sJSON,$.clients&#91;0],result<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Gets the first client.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;sJSON,$.clients&#91;*],result<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Gets all clients.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>Using Filters<\/h3>\n\n\n\n<p>Select only books cheaper than 10:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;json,$.store.book&#91;?@.price &lt; 10],cheapBooks<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Select books that contain an ISBN:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;json,$.store.book&#91;?@.isbn],withIsbn<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Get titles of books under 15:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>JSONParse&gt;json,$.store.book&#91;?@.price &lt; 15].title,titles<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3>JSONPath Best Practices<\/h3>\n\n\n\n<ul>\n<li>Always start paths with&nbsp;<code>$<\/code><\/li>\n\n\n\n<li>Remember results are arrays<\/li>\n\n\n\n<li>Check&nbsp;<code>result_count<\/code>&nbsp;before using values<\/li>\n\n\n\n<li>Build paths step by step<\/li>\n<\/ul>\n\n\n\n<p>For full explanations and more examples:<br><a href=\"https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples?utm_source=chatgpt.com\">https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2>Final Thoughts<\/h2>\n\n\n\n<p>XPath and JSONPath solve two of the most common automation problems:<\/p>\n\n\n\n<ul>\n<li><strong>XPath<\/strong>&nbsp;\u2192 finding the right element on a web page<\/li>\n\n\n\n<li><strong>JSONPath<\/strong>&nbsp;\u2192 extracting the right value from structured data<\/li>\n<\/ul>\n\n\n\n<p>Mastering these will make your Macro Scheduler scripts&nbsp;<strong>more reliable, more flexible, and easier to maintain<\/strong>.<\/p>\n\n\n\n<p>If you regularly automate websites or APIs, these two primers are essential reading.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>If you automate websites, APIs, or online services with Macro Scheduler, you\u2019ll quickly run into two recurring challenges: Two technologies solve these problems: We\u2019ve published two practical primer articles that go deep into both topics: &#x1f449;&nbsp;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 &#x1f449;&nbsp;A JSONPath Primer (with Macro Scheduler examples)https:\/\/help.mjtnet.com\/article\/555-a-jsonpath-primer-with-macro-scheduler-examples Below is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,11],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3268"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=3268"}],"version-history":[{"count":11,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3268\/revisions"}],"predecessor-version":[{"id":3280,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3268\/revisions\/3280"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=3268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=3268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=3268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}