Unable to Scroll in android when using Espresso as a automation type


#1

Hi Team,
I am trying to do scroll using Espresso automation type by uiautomator logic. here is the code I am trying.

            driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector())" +
            ".scrollIntoView(new UiSelector().text('"+textToFind+"'));"))
            .click();

and the following is the error message i got

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //*[@text='Enter City or Airport Code'] (tried for 60 second(s) with 500 milliseconds interval)

at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at testScripts.TouchActions_Android.testTouchActions(TouchActions_Android.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
 Caused by: org.openqa.selenium.NoSuchElementException: An element could not be located on the 
 page using the given search parameters.
For documentation on this error, please visit: 
https://www.seleniumhq.org/exceptions/no_such_element.html

Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘MACLTUS66036’, ip: ‘fe80:0:0:0:8f4:54b0:46ae:ea2c%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.14’, java.version: ‘1.8.0_172’
Driver info: io.appium.java_client.android.AndroidDriver

Appreciate your response.


#2

Hi,

Give a try for below code:

((FindsByAndroidUIAutomator) driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+text+"\").instance(0))").click();


#3

thanks, it worked for me.