On this page

Macro: Record and Replay Automated Actions

The Starter plan and above include Macros.

What is a Macro in Distill?

Macros allow you to record a sequence of actions performed on a web page. Some examples of webpage actions are scrolling, button clicks, or form submissions on the page. Once you record the Macro, you can replay it on the webpage.

In Distill, you can use Macros in two ways:

  1. For monitoring the desired section of the webpage, where the content displays only after performing web page actions (button click, scroll, etc.).
  2. As a Macro action after Distill checks the web page for changes. When Distill detects a change in your monitor, the Macro will replay the actions on the web page.

Use macros when the page URL doesn’t change after actions like submitting forms, sorting, filtering, logging in, or searching. Macros can replicate these actions, taking you to the desired page view.

You will need to follow two steps for monitoring webpages that need Macro:

  1. Create a Macro that records the flow of actions on the web page.
  2. Use the saved Macro and play it before monitoring the section on the web page.

Here’s a video tutorial with an example showcasing how to create a macro, record actions, and use it on a webpage monitor.

How to create a Macro?

You can create Macros from the web app or the browser extension.

  1. Click on the Macros option from the hamburger icon ☰. This opens your macro list.
Screenshot of the Watchlist with the ☰ menu open above the monitors. The menu lists Export, Import, Crawlers, Macros, Profiles, Devices, Proxies, Global Actions, Global Conditions, AI Summary and Error Actions. The ☰ button and Macros are outlined in orange.
  1. Enter a name in New Macro Name and the page URL in Start URL, then click Add New Macro. This opens the URL in Distill’s remote browser.

  2. Once the page loads, perform the web page actions to display the final content. You will also see the corresponding steps for each action in the right panel, under steps, as shown below.

    Screenshot of the recorder's right panel. The toolbar has Start Recording, Undo, Redo, Play, Step, Stop and a ⋯ menu. Below Input Variables, the steps of the Load All Reviews Macro are listed as a tree: wait_doc, assert, click #accept-cookies, cond, while and two for loops.
  3. [Optional] Click the Play button (play icon) to ensure that you have captured the correct flow of actions.

  4. Click the Save button to save the Macro.

The Macro list opens after saving a Macro and shows the newly added Macro.

Record on a dedicated cloud device

Add New Macro always opens the recorder in Distill’s cloud. To record on one of your dedicated cloud devices instead:

  1. Create the Macro as above, or pick an existing one in your macro list.
  2. Click the dropdown arrow next to Open Recorder Using and select the device.

The recorder opens in that device’s browser. The Proxy and Profile menus show only when you record in the cloud. The next time, Open Recorder Using opens the device you picked last.

How to use a Macro for monitoring?

You can use a Macro to make selections on a page for monitoring. This will work for both cloud and local monitors. To use it for a local monitor, you will have to change the device from the Option page or the Watchlist.

Here are the steps to use a Macro:

  1. In the Watchlist, click Add Monitor → Webpage. Enter the URL and click Monitor Parts of page. If the button shows another option, pick Parts of page from the dropdown next to it first.

  2. From the visual selector toolbar, click the Macro - <None> menu. This shows all the saved Macros for the URL. Select the Macro from the drop-down list. The menu then shows the Macro’s number of steps and name.

    Screenshot of the visual selector's Macro menu. Below a Search box it lists None and the Load All Reviews Macro, which is selected, then Manage Macros and Learn More.
  3. Click the play button (Play Macro) left of the Macro’s name. This plays the recorded actions and reaches the final page where you can make selections to monitor.

    Screenshot of the visual selector toolbar with the Play Macro button, outlined in orange, left of the selected Macro, 7 steps - Load All Reviews.
  4. Once the Macro finishes playing, click Select elements at the top of the right panel and select the elements to monitor. Save the selections.

  5. Configure the settings like check interval, device, and others from the Options page and click Save.

How to use Macro actions after checks?

Macro actions are available for local monitors.

You can set up Macro actions to replay a set of steps on a page once your monitor detects a change.

  1. Create a Macro as explained above to record the actions to be performed after the change is detected.
  2. Create a monitor for that web page by clicking Add Monitor → Webpage in the Watchlist.
  3. In the options page, click on Add actions and select Run Macro (for local monitor) from the actions list.
Macro Action

Some common scenarios when you can use macro actions are:

  • Automate adding items to cart when its available: You can set up a monitor to track a sold-out product. When the visual selector detects a change from “Sold Out” to “Add to Cart” on the product page, use Macro action to automate adding the item to your cart. It will open the page in a new tab and replay the actions recorded in the Macro.

Here’s a video tutorial with instructions to use macro actions:

  • Applying to a job opening: While tracking a careers page, if a role starts accepting applications, you can use Macro actions to apply for the job automatically.

  • Auto login: While monitoring pages that are accessible only when logged in, use a conditional block in a macro to check if the page displays a login form. If the login form is detected, the macro action will automatically log in to the page.

How to edit a Macro?

You can edit, add, or delete a step for an existing Macro.

  1. Open your macro list.
  2. Click Open Recorder Using for the Macro that you need to edit. The button ends with the device name, such as the cloud or a dedicated cloud device.
  3. Click the overflow icon (⋮) as shown below for a step and edit as needed. This opens a menu with options.
Screenshot of one step in the Macro's steps: click with the selector #accept-cookies and the position 24, 12. The ⋮ icon at the right end of the row is outlined in orange.
  1. The menu shows only the options that apply to that step:

    • Edit: Replace Statement (Replace Value on a value), Insert After, Insert Before, Insert At End (on a block of steps), Duplicate and Add else if after this (on an if line), Add Arguments or Add Optional Fields (when some are unset), Create Input Field (on a value), and Edit Source.
    • Play: Play Step, Play Until, and Set Breakpoint or Remove Breakpoint. See Play and debug steps.
    • Record: Start recording after this step, or Start recording inside a condition or loop.
    • Delete removes the step.
  2. To change a value, such as a step’s selector, click it. Edit it in the box that opens and click Save.

Screenshot of the click step's selector #accept-cookies open for editing. A box below it holds the selector in a text field, with Replace, Cancel and Save buttons. Save is outlined in orange.
6. Once done, click Save to save the changes made to your Macro.

Saved edits will apply to all the monitors using this Macro.

To edit the steps without opening a browser, click the Macro’s N steps link in the macro list. This opens Edit Macro with the same steps and ⋮ menus. Its menus have only the Edit and Delete options: playing and recording need the recorder.

Play and debug steps

The recorder can play the whole Macro or a part of it, so you can find the step that fails.

  • Play (play icon above the steps) plays the Macro from the start in a new tab. While it plays, use Pause and Stop.
  • Play Step in a step’s ⋮ menu plays only that step.
  • Play Until in a step’s ⋮ menu plays the Macro from the start and pauses at that step.
  • Set Breakpoint in a step’s ⋮ menu makes playback pause at that step. Remove Breakpoint clears it. To clear all breakpoints, click the ⋯ button next to Stop and select Clear Breakpoints.

When playback is paused, click Step to play the next step, or Play to continue.

Get help from the AI assistant

The Macro recorder has an AI assistant that helps you create Macros and fix errors. It can read the Macro’s steps, add, change or delete steps, and play them in the recorder’s browser to check the result.

  1. Open the recorder for a Macro.
  2. Click Ask AI at the bottom of the recorder. The chat opens in a corner of the window. Click Dock in the chat to place it beside the steps.
  3. Describe what the Macro should do, or ask the assistant to fix a step that fails.
  4. Check the steps it changed, then click Save to keep them.

What are conditions in Macros?

Within the steps in the Macro, you can add a Conditional block (IF…ELSE). It allows you to execute specific steps based on whether a condition evaluates to true or false. It is similar to IF…ELSE structure in programming languages.

You can leverage Macro conditional blocks in several scenarios, including but not limited to:

  • Managing Intermittent Pop-ups: You can use conditional blocks to handle pop-ups that appear sporadically. If a pop-up is detected, the macro executes a specified set of steps; otherwise, it continues with an alternate sequence.
  • Ensuring Continuous Access: For pages requiring authentication, conditional blocks can automate the login process. This is especially useful if you’re monitoring a page and find yourself logged out.

Specifically, for local monitors tracking access to password-protected pages, you may encounter session timeouts that result in being logged out. In these instances, you can insert an IF…ELSE conditional block within your macro to check the login status. If logged out, the macro can automatically execute steps to log back in, preventing errors and ensuring continuous monitoring.

How to add conditions in Macro steps?

Steps to add if…else in the Macro recorder:

  1. Click the ⋮ menu of the step where you want to add a condition and open Insert After or Insert Before. Under Control Flow, select Conditional (if/else).
Screenshot of the Edit Macro dialog with the ⋮ menu of the wait_doc step open. Insert After is highlighted, and its submenu lists Conditional (if/else), For Loop and While Loop under Control Flow, then browser actions such as click, drag and fill. Conditional (if/else) is outlined in orange.
  1. A cond block is added. Click the arrow next to cond to expand it. It has an if line with a condition and a body. In the example below, the condition checks whether the page has a .newsletter-popup element.
Screenshot of an expanded cond block. Below cond are an if line, a condition row with element_exists .newsletter-popup, and a body row with 1 step.
  1. To change the condition, click the ⋮ menu on the condition row and select Replace Value. To combine it with more conditions, select and, or or not under Surround with in the same menu. To add steps to the body, select Insert At End in the ⋮ menu of body, or Insert After in the ⋮ menu of a step in the body.

There is a provision to “Add clause” in Macro steps. This gives you the ability to check for multiple conditions when each condition leads to a different outcome of steps. Follow these steps to add a clause with an ELSE…IF

  1. Click the ⋮ menu on the if (or else if) line and select Add else if after this.
Screenshot of an expanded cond block that already has an if and an else if clause. The ⋮ menu of the if line is open with Replace Value, Add else if after this, Duplicate, Edit Source and Delete. Add else if after this is outlined in orange.
  1. An else if line with its own condition and body is added. Its body runs when the conditions above it are false and its own condition is true. In the example below, the Macro closes the newsletter pop-up if it shows, or else picks a region if the region picker shows.
Screenshot of a cond block with two clauses. The if clause checks element_exists .newsletter-popup and its body clicks .newsletter-popup .close. The else if clause checks element_exists #region-picker and its body selects United States in #region-picker.

How to use Assert expression in the Macro recorder?

Assert expression is used for error-checking during the macros execution.

  • Use assert to verify the webpage’s expected behavior when the macro steps are being executed.
  • If an assertion fails due to any missing response to the step in the macro, it will raise an exception to halt execution of next steps.
  • Assert will error out the monitor with the error code set in the step, E_ASSERT by default.

For example, verifying if a page exists before beginning to check any section inside it.

For this, add an assert step whose condition checks for an element that only the real page has. In the example below, the condition is element_exists #reviews. If the page has no #reviews element, the assert fails with the error code E_ASSERT and the message “Page does not exist”.

Screenshot of an expanded assert step with three rows: condition element_exists #reviews, error_code E_ASSERT, and message Page does not exist.

When you run the monitor, and page is not found, the macro will assert an error and stop further checks from executing.

Using assert expression in the macro steps

What are Loops in Macros?

Loops in macros allow you to automate repetitive tasks by repeatedly executing a block of actions. There are two primary types of loops that you can use in Distill macros: For Loops and While Loops. Each serves different purposes depending on the nature of the repetition and the conditions under which the loop should run.

For Loops

For loops are used to iterate over a set of values or elements. They are particularly useful when you need to perform an action a specific number of times or over an array of elements. In Distill, you can use For Loops in several ways:

  1. Iterate over elements: If a webpage has multiple similar elements (like items in a list or tags), you can set a For Loop to perform actions on each element one by one.
  2. Iterate using a range: You can specify a range with the range() function to execute the loop a certain number of times. This is handy for tasks such as clicking a button multiple times or navigating through pagination by incrementing page numbers.

While Loops

While Loops evaluate a condition before each iteration, and the loop continues until the condition is no longer true. This type of loop is ideal for situations where the number of iterations isn’t known in advance and must be determined dynamically. For example, you might use a While Loop to continue clicking a “Load More” button until it no longer appears on a webpage.

How to add Loops in Macro steps

Steps to add a While Loop in the Macro recorder:

  1. Click the ⋮ menu of the step where you want the loop and open Insert After or Insert Before. Under Control Flow, select While Loop.

  2. A while block is added. Click the arrow next to while to expand it. It has a condition and a body. Set the condition and add steps to the body as for a conditional block.

Screenshot of an expanded while block. Its condition is element_exists button.load-more, and its body has two steps: click button.load-more and wait_for_duration 2.

Steps to add For loop in the Macro recorder:

  1. Click the ⋮ menu of the step where you want the loop and open Insert After or Insert Before. Under Control Flow, select For Loop.

  2. A for block is added. Click the arrow next to for to expand it. It has a variable, an iterable and a body.

  3. To execute the loop a predetermined number of times, utilize the range function. For example, to repeat an action five times, use range(5). This sets the loop to execute the body’s steps five times, assigning the iterator variable values from 0 to 4 on each iteration.

Screenshot of an expanded for block with variable i and iterable range 5. Its body has two steps: scroll #reviews and wait_for_duration 1.
  1. To cycle through a collection of elements matching a specific selector, choose a selector as the iterator. The loop will then process the steps in the body for each element found by the selector. The iterator variable will be assigned the selector for each element during each iteration. In the example below, the click step uses $review to click each element in turn.
Screenshot of an expanded for block with variable review and the selector .review-card button.read-more as its iterable. Its body has one step: click $review.

Note: By default, the loop’s iterator variable is named item, but it can be renamed as needed.

Steps and their descriptions

  1. CLICK (click): Simulates a mouse click on a specified element, such as a button or a link, triggering any associated actions or events.
  2. DRAG (drag): Replicates a drag-and-drop action by clicking, holding, and moving an element from one location to another within the browser.
  3. FILL (fill): Fills a form field, such as a text box, with the specified value.
  4. FOCUS (focus): Sets the focus on a specified element, like an input field or a dropdown menu, making it the active target for user interactions.
  5. GO_BACK (go_back): Goes back to the previous page in the browser history, like the browser’s back button.
  6. KEYPRESS (keypress): Simulates a keyboard key press event on a focused element, such as typing a letter or pressing Enter.
  7. MOUSEMOVE (mousemove): Mimics the movement of the mouse pointer over a specified element, triggering any related hover effects or events.
  8. OPEN (open): Opens a specified URL in the browser, navigating to the desired web page.
  9. SCROLL (scroll): Scrolls the browser window to a specified position or element, bringing the target into view.
  10. SELECT (select): Selects an option within a dropdown menu or similar element, making it the active choice.
  11. TYPE (type): Simulates typing text into a focused input field, such as a text box or search bar.
  12. WAIT_DOC (wait_doc): Pauses the macro execution until the web page’s content is fully loaded.
  13. WAIT_FOR_DURATION (wait_for_duration): Introduces a pause in the macro execution for a specified number of seconds.
  14. WAIT_FOR_ELEMENT (wait_for_element): Waits for a specified element to become available on the web page before proceeding with the macro execution.

Troubleshooting & how to check if a Macro is working correctly

When you replay a Macro, the sequence of steps will execute and successfully executed steps will have a green check mark. If a Macro is working correctly you will see a green check mark against all the recorded steps.

Macros error out usually when:

  • The page didn’t load correctly.
  • The page loads correctly but the page is a different version of the page that cannot be handled with current recorded steps.
  • The page loaded correctly but the elements’ identifiers used to build selectors have changed. The steps fail by not being able to locate the elements correctly.

If you encounter an error, you will see that the Macro does not proceed beyond the step that has an issue. If a monitor is associated to a Macro with an issue, its check fails with the failed step’s own error code, such as E_ELEMENT_NOT_FOUND or E_ASSERT. The check fails with E_MACRO when the error has no code and is not a timeout, network or invalid selector error, or when the Macro runs longer than 30 minutes. To learn more about the issue, click the time in the monitor’s row in the Watchlist to open its Check log, then click the error entry. The check details open in a new tab with the error details. When the check saved the Macro’s steps, the page also lists them and marks the step that failed.

Screenshot of a monitor's check log menu. It lists checks by time, newest first; the three newest show E_MACRO in red. The newest error entry is outlined in orange.

The check details show the error in Error Details and mark the failed step, and the blocks that hold it, with a red cross. You can go back to replay the Macro and find out the step with issues and either edit or re-record the step.

Screenshot of a failed check's details page. On the left, Error Details shows E_MACRO, the error message and the step it stopped at, above the list of checks. On the right, the Macro's steps are listed with red crosses on the steps list, the second for loop, its body and the click step that failed, which also shows its error message. Error Details and the failed click step are outlined in orange. Click the image to open it at full size.

Need help?

If you need help with a macro or have a URL that is not handled yet, feel free to ask in the Distill forum. You can explore existing discussions or post to get help on any topic.

For instructions on how to import, export, and edit macros on a webpage using JSON refer this video.

Suggested reading

Below are some related resources for more details on how to use conditions within macros:

Video guide to check login status of page using conditions in Macros.

Video tutorial to use conditional IF block to handle infrequent Pop-ups while adding Macros steps.

Discussion thread on Conditions in Macros for further reading.

How to monitor webpages with login and password?

Was this article helpful? Leave a feedback here.