private ViewGroup mockViewGroup(int id, ViewGroup ...viewChildren) {
        ViewGroup view = mock(ViewGroup.class);
        final ArrayList<ViewGroup> children = new ArrayList<ViewGroup>(Arrays.asList(viewChildren));

        when(view.getId()).thenReturn(id);
        when(view.getChildCount()).thenReturn(children.size());
        when(view.getChildAt(anyInt())).then(new Answer<View>() {
            @Override
            public View answer(InvocationOnMock invocationOnMock) throws Throwable {
                return children.get((Integer) invocationOnMock.getArguments()[0]);
            }
        });

        return view;
    }
Helper to do the actual searching.
selendroid-server/src/test/java/io/selendroid/server/model/internal/AbstractNativeElementContextTest.java