Block reference / UI Interaction
Element exists
Whether an element is on the phone's screen: true or false.
Only in
WarpX Phone
Element exists answers one question: is this element on screen now, or within a short wait? Use it for what sometimes shows and sometimes does not, such as a promotion pop-up, a sign-in screen or a sold-out label, and branch on the answer with Conditions. Unlike the browser's Element exists, it has one output and answers with a value rather than by branching.
true.Settings
- Selector
The element to act on. Inspect opens the Inspector for the phone picked in the editor's toolbar: pick the element, then Use in block for its locator, which still finds the element after the app changes, or Use XPath. You can also write an XPath such as
//android.widget.Button[@text='Sign in'], or plain text, which means the element whose text is exactly that; Verify looks for it on the phone now and says whether it found one, several or none.Example//android.widget.ImageButton[@content-desc='Close']- Save the answer (true / false) to a variable
Also stores the answer,
trueorfalse, in a workflow variable.ExampleChecked- Variable namewhen Save the answer (true / false) to a variable is on
The variable to write. Later blocks read it as
{{variables.promoShown}}, for example in a Conditions path.ExamplepromoShown- Wait up to (ms)
How long to keep looking, in milliseconds, up to
120000. The default0looks once.Example3000- Delay (ms)
A pause after the block finishes, before the next block starts. Write one number such as
1000, or a range such as1000,3000for a random pause in that range on each run.Example0
Every block also has the shared block settings — a description, Disable block and what to do on an error, and Finding elements on a phone explains selectors, Inspect and Verify in more depth. Fields that take text accept data from earlier blocks.
What it hands on
Hands on true or false as {{prevBlockData}}, and writes it to the variable when asked. Always leaves by its single output.
Example: Close a promotion pop-up only when it shows
- Start
- Start app
- Element exists
- Conditions
- Touch
- Pick the phone in the editor's toolbar and add a Start app block for the shop app.
- Add an Element exists block, click Inspect, pick the pop-up's close button and press Use XPath.
- Set Wait up to (ms) to
3000, tick Save the answer (true / false) to a variable and name itpromoShown. - Add a Conditions block with a path
{{variables.promoShown}}Equalstrue, connected to a Touch on the same close button. - Connect the Touch and the Fallback of Conditions to the rest of the flow, and press Run.
Good to know
- A missing element is an answer,
false, not a failure. The block still fails when it cannot look at all, for example without the WarpX agent or with a selector that is not valid. - A locator from Use in block can stand in an element that looks like the one it was made from when the app has changed. That keeps a flow working after an update, but it can also answer
truefor a look-alike; use an XPath when only the exact element will do. - Element blocks read the screen through the WarpX agent, which the Devices page installs on the phone. Without it the block fails with
AGENT_NOT_INSTALLED. - What Selector accepts: anything starting with
/or(/is an XPath, evaluated as full XPath 1.0 over the screen's elements with the attributes Appium uses (text,resource-id,content-desc,class,package,boundsand flags such asclickable), socontains()andstarts-with()work. Text starting with{or[is read as JSON: the locator Use in block writes, or a selector such as{"res": "com.example.shop:id/search_box"}. Anything else is the exact, case-sensitive text of an element. There is notext=orid=shorthand:text=Sign inlooks for an element whose text istext=Sign in.
See also
- Wait for element — Wait until an element shows on the phone's screen, or until it has gone.
- Find text (dump) — Look for text among the screen's elements, and say whether it is there or tap it.
- Read element — Read an element's text, description, id, position or state, or count how many match.
- Conditions — Send the run down one of several paths, depending on values, page elements or code.