Block reference / Control flow
Element exists
Check whether an element is on the page and continue by one of two outputs.
In both apps
WarpX Browser
WarpX Phone
Use Element exists when a page sometimes shows something and sometimes does not: a cookie banner, a login form, a sold-out label. It looks for the element, retries a few times if you ask it to, and leaves by the top output when it finds it and the bottom output when it does not.
Settings
- Description
A note shown on the block in the canvas.
ExampleCookie banner shown?- Element Selector
The CSS selector or XPath of the element to look for. You can pick it on the page with the selector button next to the label.
Example#cookie-accept- Mark element
When on, an element this block has found before is ignored the next time the block runs. Useful inside a loop. Only offered for CSS selectors.
ExampleUnchecked- Try for
How many more times to look after the first try, if the element is not there yet.
Example3- Timeout (milliseconds)
How long to wait between tries.
Example1000- Throw an error if doesn't exist
When on, a missing element fails the block with "Can't find an element with the selector" instead of leaving by the bottom output.
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
Top output when the element is found; bottom output ("Executes when the element doesn't exist") when it is not. The log shows the branch as found or not found.
Example: Accept a cookie banner only when it appears
- Start
- New tab
- Element exists
- Click element
- Get text
- Add a New tab block with the shop's URL.
- Add an Element exists block with Element Selector
#cookie-accept, Try for3and Timeout (milliseconds)1000. - Connect the top output to a Click element block on
#cookie-accept. - Connect both the Click element block and the bottom output of Element exists to a Get text block on
h1, so the run goes on either way.
On WarpX Phone
- This block does nothing useful on WarpX Phone: it looks in a web page, and a phone run has none, so it fails. Use the phone's Element exists or Wait for element block, which look on the phone's screen.
Good to know
- The block looks once, then Try for more times, waiting Timeout (milliseconds) after each miss. With the example settings that is up to four looks and about four seconds before it leaves by the bottom output.
- If all the tries together take longer than about five seconds, WarpX Browser asks the page a second time and the whole check starts over. Keep Try for plus one, times Timeout (milliseconds), under five seconds, or use a Delay first.
- It needs an open tab in the profile's browser.
- To check several things at once, or combine an element with a value, use Conditions with Element exists in the condition builder.
See also
- Conditions — Send the run down one of several paths, depending on values, page elements or code.
- Click element — Click an element on the page, with human-like mouse movement by default.
- While loop — Keep running a stretch of blocks while a condition holds.