Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've fixed it by overriding a <code>UiScrollable</code> class.</p> <pre><code>public class UiScrollable extends com.android.uiautomator.core.UiScrollable { public UiScrollable(UiSelector container) { super(container); } @Override public boolean scrollIntoView(UiSelector selector) throws UiObjectNotFoundException { if (exists(getSelector().childSelector(selector))) { return (true); } else { System.out.println("It doesn't exist on this page"); // we will need to reset the search from the beginning to start search scrollToBeginning(getMaxSearchSwipes()); if (exists(getSelector().childSelector(selector))) { return (true); } for (int x = 0; x &lt; getMaxSearchSwipes(); x++) { System.out.println("I'm going forward a page: " + x); if(!scrollForward() &amp;&amp; x!=0) { // x!=0 is the hack return false; } if(exists(getSelector().childSelector(selector))) { return true; } } } return false; } } </code></pre> <p>I've copied the source from: <a href="http://android.googlesource.com/platform/frameworks/testing/+/jb-mr0-release%5E1/uiautomator/library/src/com/android/uiautomator/core/UiScrollable.java">UiScrollable.java</a> (which may be outdated at some point, beware) and simply changed the <code>if(!scrollForward() &amp;&amp; x!=0)</code> line.</p> <p>From my observations, in the case of the example code on Google's ui testing page that scrolls the apps screen for the settings app, the <code>scrollForwards()</code> method fails on the first attempt. God knows why.</p> <p>The above simply says if it fails on the first scroll, carry on regardless. If it fails to scroll on the second scroll, then it does in fact return a failure.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload