Dropdown Value Selection Using Espresso Android With Dynamic Element Id's
Solution 1:
I was struggling with this issue and I found that you need to use a combination of withText
to select the view and an option called RootMatchers.isPlatformPopup()
which will try and find the matching text within views such as the autocomplete view and it is actually designed for this purpose.
It should look something like;
onView(withText("matching text"))
.inRoot(RootMatchers.isPlatformPopup())
.perform(click());
Solution 2:
You maybe be able to just do
onData(anything())
.atPosition(1)
.perform(click());
However, that assumes only one adapter view. If you have others, you'll need to somehow pick out that ListPopupWindow$DropDownListView
.
I know you said all IDs are dynamic, but is there some ancestor view which you could pick out by ID? If so, you could do something like
onData(anything())
.inAdapterView(isDescendantOfA(withId(someAncestorId)))
.atPosition(1)
.perform(click());
As a last resort, we could match on class name, but it would be a bit fragile:
onData(anything())
.inAdapterView(withClassName(equalTo(
"android.widget.ListPopupWindow$DropDownListView")))
.atPosition(1)
.perform(click());
Solution 3:
A combination of both previous answers seems to work for me:
Espresso.onData(Matchers.anything())
.inRoot(RootMatchers.isPlatformPopup())
.atPosition(1)
.perform(ViewActions.click())
Post a Comment for "Dropdown Value Selection Using Espresso Android With Dynamic Element Id's"