SAP — Element exists
SAP — Element exists
Section titled “SAP — Element exists”Type: sap-element-exists · Package: SAP Activities v1.0.5 · Output: boolean
Checks whether an element exists on the current SAP screen and returns true or false. It doesn’t fail if the element isn’t there: it just returns false. It is the way to handle what sometimes shows up —an unexpected dialog, a warning, a field that only appears in certain cases— and decide what to do.
How it works
Section titled “How it works”It first waits for SAP to finish whatever it is processing (so it doesn’t look at the screen from before the last action) and then looks up the element by its selector once: it doesn’t wait for it to appear and doesn’t use elementTimeout. The result usually feeds an If.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | Element to look for. Ex: "wnd[1]" to know whether a modal window is open. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
session | ZoanSapSession | — | SAP session. Omit it inside the body of an SAP — Attach or SAP — Log on. |
Output
Section titled “Output”Returns a boolean: true if the element exists on the current screen, false if not.
Common errors
Section titled “Common errors”It doesn’t fail because the element is missing: it returns false then. It only fails if the selector arrives empty ('selector' is required.) or with the errors common to all activities, such as a missing session.
Example
Section titled “Example”Read and close a dialog only if it appears:
SAP Element Exists selector = "wnd[1]" → output: hasDialogIf condition = hasDialog └─ then: SAP Get Text selector = "wnd[1]/titl" → output: dialogTitle Log message = "Dialog: " + dialogTitle SAP Close ModalRelated activities
Section titled “Related activities”- SAP — Wait for element — wait for an element to appear, and fail if it doesn’t.
- SAP — Close modal — close the dialog you found.
- SAP — Get text — read the element’s text.
- SAP — Read status bar — another way to find out what happened.