Java – espresso ONDATA error executing load adapter data on view

I have an application with listview. I want to find LinearLayout, id = order_ untake_ jijia_ listview_ jia

The code is:

onData(withClassName(endsWith("ListView")))
            .inAdapterView(allOf(withId(R.id.order_untake_jijia_listview_ll),hasSibling(withText("9.0"))))
            .atPosition(0).onChildView(withId(R.id.order_untake_jijia_listview_jia));
            dataInteraction.perform(ViewActions.click());

But I made a mistake:

Error performing 'load adapter data' on view '(with id: com.edaixi:id/order_untake_jijia_listview_ll and has sibling: with text: is "9.0")'.
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(is assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "LinearLayout{id=2131493753,res-name=order_untake_jijia_listview_ll,visibility=VISIBLE,width=170,height=50,has-focus=false,has-focusable=false,has-window-focus=true,is-clickable=false,is-enabled=true,is-focused=false,is-focusable=false,is-layout-requested=false,is-selected=false,root-is-layout-requested=false,has-input-connection=false,x=572.0,y=25.0,child-count=3}"

Solution

You are using ondata.com incorrectly

Inadapterview is used to match specific adapter view instances that contain data When you need to display multiple lists on the screen, you need to do so For example, if you have a name called r.id LIST1's listview and the second r.id List2, you can say ONDATA (is ("the string")) Inadapterview (withid (r.id.list1)) matches the objects in the first list

If you only need to click a single item in the adapter, you usually do not need to specify a subview in these cases You usually use onchildview to assert subview items, or if you happen to have a separate dedicated click listener on the subview

Therefore, it seems that your situation is too complex, and you should be able to update the code to the following:

onData(instanceOf(MyCustomClassOfObjectsInAdapter.java))
    .atPosition(0)
    .perform(click());

If this does not solve your problem, please provide some layout codes of list items, as well as the main screen layout including listview, as well as screenshots with display examples, and clarify what you want to try. Match / act / assert, I can try to guide you to complete the correct set of methods you need

Hope to help!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>