** In my script scrolling is happening very first ,so that I am not able to perform some operation on the desired element. How to stop scrolling when the element is visible.** Please have a look on my code.
@Aleksei it’s working like charm…So I think this is the best way to scroll down compare to findByuiAutomator, as per the text and there will be no worries of moving fast and missed some element. But it’s taping on that particular element .how can I avoid tapping ,I want only to scroll…Thanks In advance
@Aleksei sorry I just did it the wrong way and its working fine now… .we can move to up and down with this single piece of code which looks more better than what I was trying before.Thanks a lot:
And one more doubt: to move both lefts and right in a horizontal way, then can we use the touch action functions like getting the x and y value. or If there is any other way to do. if yes can you please provide the sample code …thanks in advance
List<AndroidElement> elementList = driver.findElements(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceIdMatches(\".*id/list\")).setAsHorizontalList().setMaxSearchSwipes(5).scrollIntoView("
+ "new UiSelector().text(\"" + title + "\"))"));
This code will work for vertical scroll,but for horizontal scroll unable to perform until exact text found.
Dimension dsize=driver.manage().window().getSize();
int startx =(int)(dsize.width0.80);
int endx =(int)(dsize.width0.10);
int starty =(int)(dsize.height/2);
for(int i=0;i<2;i++){
driver.swipe(startx, starty, endx, 0, 2000);
}
Please find the attached screenshot here have to scroll from category Burger -Horizontal scroll
public void HorizontalSwipe (AndroidDriver driver,int times,double percentage)
{
Dimension size =driver.manage().window().getsize();
int height = size.getHeight();
int width= size.getWidth();
int y=(int)(height * percentage);
int startx=(int)(width * 0.75);
int endx=(int)(width * 0.20);
Usage:
HorizontalSwipe(driver,3,0.40);
3 -No of times to be scrolled
Here 0.40 means 40% of screen Height(Y axis)
Y axis can be calculated based on 0 to 100 percentage scale ,where Y axis must be changed depend on height.
For Example:
Attached screenshot we have Category Chicken which comes under 40% of screen height.