public class By
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static MatchFinder |
allOf(MatchFinder... finders)
Evaluates given
finders in short-circuit fashion in the order
they are passed. |
static MatchFinder |
any()
Matches any UiElement.
|
static MatchFinder |
anyOf(MatchFinder... finders)
Evaluates given
finders in short-circuit fashion in the order
they are passed. |
static ChainFinder |
chain(Finder first,
Finder second)
Returns a finder that uses the UiElement returned by first Finder as
context for the second Finder.
|
static MatchFinder |
className(java.lang.Class<?> clazz)
Matches a UiElement by class name.
|
static MatchFinder |
className(java.lang.String className)
Matches a UiElement by class name.
|
static MatchFinder |
contentDescription(java.lang.String contentDescription)
Matches a UiElement by content description.
|
static MatchFinder |
contentDescriptionContains(java.lang.String substring)
Matches a UiElement whose content description contains
substring . |
static MatchFinder |
is(Attribute attribute)
Matches a UiElement whose
attribute is true . |
static MatchFinder |
not(Attribute attribute)
Matches a UiElement whose
attribute is false or is not set. |
static MatchFinder |
not(MatchFinder finder)
Matches a UiElement that does not match the provided
finder . |
static MatchFinder |
packageName(java.lang.String name)
Matches a UiElement by package name.
|
static MatchFinder |
resourceId(int resourceId)
Matches a UiElement by a resource id defined in the AUT.
|
static MatchFinder |
resourceId(java.lang.String resourceId)
Matches a UiElement by the string representation of a resource id.
|
static MatchFinder |
selected()
Matches a UiElement that is selected.
|
static MatchFinder |
text(java.lang.String text)
Matches a UiElement by the exact text.
|
static MatchFinder |
textContains(java.lang.String substring)
Matches a UiElement whose text contains
substring . |
static MatchFinder |
textRegex(java.lang.String regex)
Matches a UiElement whose text matches
regex . |
static MatchFinder |
withAncestor(MatchFinder ancestorFinder)
Matches a UiElement whose ancestor matches the given ancestorFinder.
|
static MatchFinder |
withChild(MatchFinder childFinder)
Matches a UiElement which has a visible child matching the given
childFinder.
|
static MatchFinder |
withDescendant(MatchFinder descendantFinder)
Matches a UiElement whose descendant (including self) matches the given
descendantFinder.
|
static MatchFinder |
withParent(MatchFinder parentFinder)
Matches a UiElement whose parent matches the given parentFinder.
|
static MatchFinder |
withSibling(MatchFinder siblingFinder)
Matches a UiElement which has a visible sibling matching the given
siblingFinder.
|
static ByXPath |
xpath(java.lang.String xPath)
Matches by XPath.
|
public static MatchFinder any()
public static MatchFinder is(Attribute attribute)
attribute
is true
.public static MatchFinder not(Attribute attribute)
attribute
is false
or is not set.public static MatchFinder resourceId(int resourceId)
public static MatchFinder resourceId(java.lang.String resourceId)
public static MatchFinder packageName(java.lang.String name)
public static MatchFinder text(java.lang.String text)
public static MatchFinder textRegex(java.lang.String regex)
regex
.public static MatchFinder textContains(java.lang.String substring)
substring
.public static MatchFinder contentDescription(java.lang.String contentDescription)
public static MatchFinder contentDescriptionContains(java.lang.String substring)
substring
.public static MatchFinder className(java.lang.String className)
public static MatchFinder className(java.lang.Class<?> clazz)
public static MatchFinder selected()
public static ByXPath xpath(java.lang.String xPath)
XPath is the domain-specific-language for navigating a node tree. It is
ideal if the UiElement to match has a complex relationship with surrounding
nodes. For simple cases, withParent(io.appium.droiddriver.finders.MatchFinder)
or withAncestor(io.appium.droiddriver.finders.MatchFinder)
are
preferred, which can combine with other MatchFinder
s in
allOf(io.appium.droiddriver.finders.MatchFinder...)
. For complex cases like below, XPath is superior:
<View><!-- a custom view to group a cluster of items -->
<LinearLayout>
<TextView text='Albums'/>
<TextView text='4 MORE'/>
</LinearLayout>
<RelativeLayout>
<TextView text='Forever'/>
<ImageView/>
</RelativeLayout>
</View><!-- end of Albums cluster -->
<!-- imagine there are other clusters for Artists and Songs -->
If we need to locate the RelativeLayout containing the album "Forever"
instead of a song or an artist named "Forever", this XPath works:
//*[LinearLayout/*[@text='Albums']]/RelativeLayout[*[@text='Forever']]
xPath
- The xpath to usepublic static ChainFinder chain(Finder first, Finder second)
typically first Finder finds the ancestor, then second Finder finds the target UiElement, which is a descendant.
Note that if the first Finder matches multiple UiElements, only the first match is tried, which usually is not what callers expect. In this case, allOf(second, withAncesor(first)) may work.public static MatchFinder allOf(MatchFinder... finders)
finders
in short-circuit fashion in the order
they are passed. Costly finders (for example those returned by with*
methods that navigate the node tree) should be passed after cheap finders
(for example the ByAttribute finders).public static MatchFinder anyOf(MatchFinder... finders)
finders
in short-circuit fashion in the order
they are passed. Costly finders (for example those returned by with*
methods that navigate the node tree) should be passed after cheap finders
(for example the ByAttribute finders).public static MatchFinder withParent(MatchFinder parentFinder)
xpath(java.lang.String)
.public static MatchFinder withAncestor(MatchFinder ancestorFinder)
xpath(java.lang.String)
.public static MatchFinder withSibling(MatchFinder siblingFinder)
xpath(java.lang.String)
.public static MatchFinder withChild(MatchFinder childFinder)
xpath(java.lang.String)
.public static MatchFinder withDescendant(MatchFinder descendantFinder)
xpath(java.lang.String)
.public static MatchFinder not(MatchFinder finder)
finder
.