I am using appium 1.6.3, and IOSDriver, what are the ways available to scroll to the particular element on page
Environment
Appium version : 1.6.3
Desktop OS/version used to run Appium: 10.12 (16A323)
npm version : 3.10.9
Mobile platform/version under test: 10.0.2(14A456)
Real device or emulator/simulator: Real device
this is what we did in c# as a separate method to be called in any test suite
//Sleep needed in the cases of navigating away from a screen and coming back to. This gives the driver a chance to catch up.
Thread.Sleep(700);
try
{
//UiSelector arguments must only call âscrollIntoViewâ method or methods on UIScrollable whcih return UiScrollable or UiObject objects
return driver.FindElement(MobileBy.AndroidUIAutomator(ânew UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(â" + selector + ââ).instance(0))"));
}
catch
{
//Added because sometimes Android doesnât scroll all the way
IWebElement frame = driver.FindElements(By.ClassName(âandroid.widget.ListViewâ)).ElementAt(0);
int startx = frame.Location.X + (frame.Size.Width / 2);
int starty = frame.Location.Y + ((frame.Size.Height / 2) - 5);
int endx = startx;
int endy = starty -100;
driver.Swipe(startx, starty, endx, endy, 400);
I tried implementing your solution but it just scrolls up, and not down as I expect. I also tried increasing the pixels, and changing the plus to minus as i assumed it will change the direction but it did not. Could you please help me with this ?
This is what I created to use throughout my test suite.
public static void scrollToElement(IOSDriver driver,String elementName1, String elementName2) {
WebElement abc = driver.findElement(By.name(elementName1));
WebElement abc2 = driver.findElement(By.name(elementName2));
int x = abc.getLocation().getX();
int y = abc.getLocation().getY();
int x1 = abc2.getLocation().getX();
int y1 = abc2.getLocation().getY();
driver.swipe(x1, y1, x, y, 1);
}
Basically, Element 1 is an element that is visible on the screen somewhere at the top and Element 2 is visible on the screen somewhere towards the bottom.
FAILED: testregistration
java.lang.NullPointerException
at defaultproject.wataap.testregistration(wataap.java:82)
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:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0