Module appium_client::find
source · Expand description
Find API for locating elements on screen
This API can be used to find elements on screen or in a known parent.
Basic usage
// create capabilities & client
let mut capabilities = AndroidCapabilities::new_uiautomator();
let client = ClientBuilder::native(capabilities)
.connect("http://localhost:4723/wd/hub/")
.await?;
// locate an element (find it)
let element = client
.find_by(By::accessibility_id("Click this"))
.await?;
// locate all matching elements by given xpath
let elements = client
.find_all_by(By::xpath("//*[contains(@resource-id, 'test')]"))
.await?;
Notice that if you wish to get only one element (the first match), you can use AppiumFind::find_by. If you want all matches on a screen, you use AppiumFind::find_all_by.
Custom locator strategy
If none of the options available in By work with your driver, then you might use By::custom_kind to specify custom location strategy (and search query).
Using By::custom_kind is basically the same as using any other By variant, but you need to write more and the compiler won’t tell you that you made a typo.
Some Appium docs on the matter of locators (selectors): https://appium.github.io/appium.io/docs/en/writing-running-appium/finding-elements/
Example:
// locate an element (find it)
let element = client
.find_by(By::accessibility_id("Find me"))
.await?;
// do the same, but more explicitly
let element = client
.find_by(By::custom_kind("accessibility id", "Find me"))
.await?;
Structs
Enums
- Locators supported by Appium