How to Scroll down to select particular contact from Contacts?

I am trying to select exact contact from Address Book in Android, I wrote the function to scroll down in Contacts but it is not scrolling down. I am trying it with AndroidDriver.
Once it will scroll to exact contact, how it can select all information by clicking on contact like FirstName, LastName, Email, PhoneNumber?
How can I achieve this? can u please suggest me other remaining code?
Here is my code snippet,

public void test() {
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElement(By.name(“Contacts”)).click();
MobileElement abc = (MobileElement)driver.findElement(By.className(“android.widget.TextView”));
abc.swipe(SwipeElementDirection.UP, 6000);
}

Ankit,

  • check if target element is on screen (using element.isDisplayed()), if present click it
  • if not present, scroll a bit and then click (put this in while loop)

To scroll you can also use TouchAction class, Javascript executor is also used,
can try another swipe like driver.swipe(startX, startY, startX, endY, 1000);

#E.g.
TouchAction touch = new TouchAction(driver);
touch.press(startElement).waitAction();
touch.moveTo(endElement).release();
touch.perform();

// to move down in contact list
List listOfElements = // get list of contacts using xpath or id etc
MobileElement startElement = listOfElements.size() - 1 //bottom contact
MobileElement endElemnt = listOfElements.get(0) //top contact

Thanks @sheetal0123,
I am trying to automatically select contact from Phonebook,
I wrote the code as per your E.g.
But its not working, Here I attached my updated code, can u please look at that and let me know some changes.

                 do {
			//List<WebElement> we = driver.findElements(By.className("android.widget.TextView"));
			if(driver.findElement(By.name("Amit Pandya Boston")).isDisplayed()) {
				driver.findElement(By.name("Amit Pandya Boston")).click();
			}
			else {
				//Get the size of screen
				size = driver.manage().window().getSize();
				//System.out.println(size);
				
				//find start and end point from screen's width and height
				//find startY and endY point which is at bottom side of screen
				int startY = (int) (size.height * 0.80);
				int endY = (int) (size.height * 0.20);
				
				//find startX point form where you want to start swipe. It is mostly in middle of screen.
				int startX = size.width / 2;
				
				System.out.println("StartX:" + startX + "StartY: " + startY + "endY: " + endY);
				
				//swipe from bottom to Top
				driver.swipe(startX, startY, startX, endY, 1000);
			}
		} while(true);