Block reference / Control flow

While loop

Keep running a stretch of blocks while a condition holds.

In both appsWarpX BrowserWarpX Phone

Use While loop when you do not know in advance how many times to repeat: keep clicking Next while a Next link is on the page, keep waiting while a status says "Processing". It checks the condition each time the run reaches it, runs the blocks on its top output while it holds, and leaves by the bottom output when it no longer does.

The While loop block's settings, filled in as in the example below.

Settings

Description

A note shown on the block in the canvas.

ExampleWhile there is a next page
Edit condition

Opens the Condition builder, the same one Conditions uses: rows of a value, a comparison and a value, joined with AND and OR. The loop runs while the condition holds.

ExampleElement exists | a.next-page

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

What it hands on

Top output: the loop body, taken while the condition holds. Bottom output ("Executes when the condition is false"): taken once, when it no longer holds.

Example: Read every page of results until there is no Next link

  1. Start
  2. New tab
  3. While loop
  4. Get text
  5. Click element
  6. Google Sheets
Where While loop sits in the example workflow.
  1. Add a New tab block with the first results page.
  2. Add a While loop block, click Edit condition and replace the default rows with one row: Element exists with a.next-page.
  3. Connect the top output to a Get text block on .result-title with Multiple and Insert to table on.
  4. Add a Click element block on a.next-page, then connect it back into the While loop's input.
  5. Connect the bottom output to a Google Sheets block set to Append, to write what the loop collected.

On WarpX Phone

  • On WarpX Phone, Element conditions and Code in Active tab fail, because a phone run has no page. Check the screen with the phone's Element exists block, Assign to variable ticked, and loop while that variable Is truthy.
  • Runs started on phones from Run automation on the Devices page or in the Control Center are stopped after 30 minutes too.

Good to know

  • The body must lead back into the While loop's input; the block does not loop by itself.
  • A new While loop starts with two rows that compare an empty value with an empty value, which is always true. Left like that, it never stops.
  • There is no limit on the number of rounds. Runs WarpX Browser starts on profiles for you, from the Profiles page or a schedule, are stopped after 30 minutes; a run started from the editor keeps going until you stop it.
  • In this example the last page is never read, because the loop ends as soon as the Next link is gone. Add a Get text after the bottom output if you need it.
  • Element checks need an open tab.

See also

  • Conditions — Send the run down one of several paths, depending on values, page elements or code.
  • Repeat task — Run a stretch of blocks a set number of times, then carry on.
  • Element exists — Check whether an element is on the page and continue by one of two outputs.