Skip to content

Element Exists

Type: page-element-exists  ·  Package: Browser v1.0.9  ·  Output: bool

Checks whether an element exists and is visible on the page, and returns true or false. Unlike other activities, it doesn’t fail if the element isn’t there: it simply returns false. It’s how you handle pages that sometimes show something and sometimes don’t — an error message, a cookie banner, a search result.

It looks for the element by its selector. By default (timeout = 0) it does an immediate check. If you set a higher timeout, it waits up to that time for the element to appear and be visible before returning false. The result typically feeds an If.

  • If the selector matches several elements, it doesn’t fail: it looks at the first one.
  • An element that exists in the HTML but is hidden returns false.
  • It doesn’t use the project settings timeout: without timeout, the check is always immediate.
ParameterTypeDefaultDescription
selectorselector—The element to check.
ParameterTypeDefaultDescription
pageZoanPageSession—The page session. Omit it inside a body; outside, pass the session variable (e.g. page = page).
timeoutnumber0Maximum time in ms to wait for it to appear and be visible. 0: immediate check.

Returns a bool: true if the (first) element exists and is visible; false if it doesn’t exist, is hidden or didn’t appear within timeout.

Close a cookie banner only if it appears:

Page Element Exists selector = (#banner-cookies) timeout = 3000 → output: hayBanner
If condition = hayBanner
└─ then:
Page Click selector = (#aceptar-cookies)

It practically never fails because of the element: any problem while looking for it returns false. It only fails before searching:

MessageCause and fix
No elements match the selector, so the anchors cannot be applied.The selector has anchors and there were no candidates at that moment. For a check that doesn’t fail, use a selector without anchors.
'page' must be a ZoanPageSession.page is empty outside a body.
  • Wait For — wait for (and require) an element to appear.
  • If — branch on the result.