Element
Locate an Element using a Matcher. The most common is by.label
which attempts to find by accessibility label.
Usage
element(matcher, options)
Parameters
matcher
(Matcher
): Matcher to define the locator strategy.options
(Object?
):options.sliderRange
(Tuple<Number, Number>?
): Provides cross-platform consistency when retrieving the value of a slider. The first number in the tuple is the minimum value, while the second number is the maximum value of the slider (e.g.[0, 1]
).
Returns
Promise
(Element
): The first matching element.
Support
Platform | Supported |
---|---|
iOS | Yes |
Android | Yes |
Web | Yes |
Examples
Input text.
const { element, by, expect } = require("appdriver");
(async () => {
const $input = await element(by.label("search-input"))
.typeText("Example Text");
await expect($input).toHaveValue("Example Text");
})();
Set slider value.
const { element, by, expect } = require("appdriver");
(async () => {
const $input = await element(by.label("slider"), { sliderRange: [ 0, 10 ] })
.setValue(5);
await expect($input).toHaveValue(5);
})();
Swipe up on a scroll view.
const { element, by } = require("appdriver");
(async () => {
await element(by.label("scroll-view"))
.swipeUp({ distance: 100 });
})();