Element Exists
Element Exists
Section titled “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.
How it works
Section titled “How it works”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.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | The element to check. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
page | ZoanPageSession | — | The page session. Omit it inside a body; outside, pass the session variable (e.g. page = page). |
timeout | number | 0 | Maximum time in ms to wait for it to appear and be visible. 0: immediate check. |
Output
Section titled “Output”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.
Example
Section titled “Example”Close a cookie banner only if it appears:
Page Element Exists selector = (#banner-cookies) timeout = 3000 → output: hayBannerIf condition = hayBanner └─ then: Page Click selector = (#aceptar-cookies)Common errors
Section titled “Common errors”It practically never fails because of the element: any problem while looking for it returns false. It only fails before searching:
| Message | Cause 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. |