Block reference / Control flow

Loop data

Run the blocks after it once for each row, number, list item or element.

In both appsWarpX BrowserWarpX Phone

Use Loop data to repeat the same steps over a list: rows of the workflow's table, rows read by Google Sheets, a list in a variable, JSON you paste in, a range of numbers or elements on the page. The blocks after it run once per item, and a Loop breakpoint with the same Loop ID sends the run back for the next item. Inside the loop, {{loopData.<Loop ID>}} is the current item.

The Loop data block's settings, filled in as in the example below.

Settings

Description

A note shown on the block in the canvas.

ExampleOne pass per product
Loop ID

The name of this loop. You use it in {{loopData.products}} and in the Loop breakpoint that closes the loop. Spaces are removed; if you leave it empty, a random ID is filled in.

Exampleproducts
Loop through

Where the items come from: Table, Numbers, Google Sheets, Variable, Custom data or Elements.

ExampleGoogle Sheets
Reference keywhen Loop through is Google Sheets

The Reference key (optional) you gave the Google Sheets block that read the rows. That block must run before this one.

Exampleproducts
Variable namewhen Loop through is Variable

The variable that holds the list. A list, or JSON text of a list, loops item by item. A number such as 5 loops 1 to 5. Plain text loops one character at a time.

ExampleproductUrls
Element selectorwhen Loop through is Elements

The CSS selector or XPath of the elements to loop through. Each item is a selector for one element, which you pass to blocks inside the loop.

Example.product-card
Wait for selectorwhen Loop through is Elements

Wait for the elements to appear instead of failing at once when there are none yet.

ExampleUnchecked
Selector timeout (ms)when Loop through is Elements and Wait for selector is on

How long to wait for the elements.

Example5000
Insert datawhen Loop through is Custom data

Opens a JSON editor for the list to loop through. It must be a JSON list. Import file loads a JSON or CSV file up to 1 MB; for CSV, Use the first row as keys (under the settings button) turns each row into named fields.

Example[{"url": "https://shop.example.com/p/101"}, {"url": "https://shop.example.com/p/102"}]
From numberwhen Loop through is Numbers

The first number. The editor keeps it below To number.

Example1
To numberwhen Loop through is Numbers

The last number. Both ends are included, so 1 to 10 runs ten times.

Example10
Max data to loop (0 to disable)when Loop through is not Numbers

Stop after this many items. 0 loops through all of them.

Example0
Start from indexwhen Loop through is not Numbers and Resume last workflow is off

The position to start at. The first item is 0.

Example0
Resume last workflowwhen Loop through is not Numbers

Start at the item the last run of this block had reached, instead of at Start from index.

ExampleUnchecked
Reverse loop orderwhen Loop through is not Numbers

Go through the items from last to first.

ExampleUnchecked

Every block also has the shared block settings — a description, Disable block and what to do on an error, and Finding elements explains selectors in more depth. Fields that take text accept data from earlier blocks.

What it hands on

Loop data has one output: the loop body, which runs for the current item. There is no "done" output on this block. When the items run out, the Loop breakpoint with the same Loop ID leaves by its own output. Inside the loop, {{loopData.products}} is the whole item, {{loopData.products.url}} is one field of it, and {{loopData.products.$index}} is its position, counting from 0.

Example: Read the price of every product in a sheet

  1. Start
  2. Google Sheets
  3. Loop data
  4. New tab
  5. Get text
  6. Loop breakpoint
  7. Google Sheets
Where Loop data sits in the example workflow.
  1. Add a Google Sheets block set to Get spreadsheet values, with your sheet in Spreadsheet Url or ID, Range Products!A1:B50, Use the first row as keys on and Reference key (optional) products. The sheet has a url column.
  2. Add a Loop data block. Set Loop ID to products, Loop through to Google Sheets and Reference key to products.
  3. Add a New tab block with New tab URL {{loopData.products.url}} and Update previously opened tab on, so every item reuses one tab.
  4. Add a Get text block on .product-price with Insert to table on.
  5. Add a Loop breakpoint with Loop ID products, and connect Get text to it.
  6. Connect the breakpoint's output to a Google Sheets block set to Append, to write the collected rows to a sheet. It runs once, after the last row.

On WarpX Phone

  • On WarpX Phone, Elements fails: there is no page to find them in. The other sources work as they do here.
  • A loop cannot move a run to another phone: every phone block acts on the phone the run is on. To work through many phones, tick them in Run automation on the Devices page or in the Control Center, and each runs the workflow on its own.

Good to know

  • Without a Loop breakpoint with the same Loop ID, the blocks after Loop data run once, for the first item, and the loop never repeats.
  • Give nested loops different Loop IDs.
  • Max data to loop counts positions from the first item, not from Start from index: start 5 with max 10 runs items 5 to 9.
  • Reverse loop order reverses the list itself, not a copy. Looping the Table in reverse also reverses the workflow's table, so later blocks and exports see it reversed. The same applies to a variable that holds a list.
  • A Variable or Custom data value that is not a list, such as a single object, fails with "Invalid data to loop through".
  • Resume last workflow saves the position after every item. The next run starts on the item the last run was on, so that item runs again. After a run that finished the loop, the next one starts on the last item; turn the option off to start over. The position is kept per block, not per profile.
  • For Numbers, Max data to loop, Start from index, Resume last workflow and Reverse loop order are hidden and not used.

See also

  • Loop breakpoint — Mark the end of a loop: go back for the next item, or leave when the loop is done.
  • Loop elements — Run the blocks after it once for each element that matches a selector, loading more as it goes.
  • Google Sheets — Read rows from a Google Sheet, keep only the ones you want, or write, append and clear cells.
  • Repeat task — Run a stretch of blocks a set number of times, then carry on.