How do I click the first item in a spinner using Robotium?

后端 未结 3 1743
误落风尘
误落风尘 2021-01-23 12:08

I am having problems scrolling up in a spinner to select the first item in a Robotium test case. Here is my code:

int pos = solo.getCurrentSpinners().get(0).getS         


        
3条回答
  •  不要未来只要你来
    2021-01-23 12:40

    The API to use here with Robotium is rather flaky, so I decided to go down the direct API route:

    instrumentation.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            Spinner spinner = (Spinner) solo.getView(resourceId);
            spinner.setSelection(position, true);
        }
    });
    

    This won't show you the popup of the Spinner, but it will select the desired item.

提交回复
热议问题