Find the element by swiping top to bottom


#1

Hi all,

APPIUM on ANDROID is the focus.
I have a scenario to be automated . Below is the scenario:

  1. Swipe from top to the bottom.
  2. Each tile has an index such as 0,1,2,3,4 and so on.
  3. I have to click on a tile with any index 0 or 1 or any index available on the screen.
    I tried using
    WebElement index = driver.findElement(By.className(“abc.abc.abc//index[1]”));
    index.click();
    But the element was not located .
    I also used the Select class

WebElement index = driver.findElement(By.className(“abc.abc.abc”));
Select sel = new Select(index);
sel.selectByIndex(2);

But this also failed.

Can anyone help me out in resolving this issue?
I have to click on the element using its index.

Regards
Tejesh


#2

Hi Tejesh,

I think in this case you can use uiselector and uiscrollable.
http://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html
http://developer.android.com/reference/android/support/test/uiautomator/UiSelector.html

In Ruby we can find the element with code like this,

find_element(:uiautomator, 'new UiScrollable(new UiSelector().scrollable(true).index(2)).getChildByText(new UiSelector().className("android.widget.TextView"), "Text")') 

If you need more details on a specific lang, you can see the code for scroll_to and scroll_to_exact in that lang bindings.

Thanks,
Donald


#3

Thanks Donald,I’m using Java, will try it out and let know.


#4

For top to bottom swiping i used following c# code it’s working fine.

//Height of ur screen.
int height = driver.Manage().Window.Size.Height; //1200

//Widhth of ur screen
int width = driver.Manage().Window.Size.Width; //720

        decimal height1 = height; //1200
        decimal width1 = width; //720
        decimal starty1 = Decimal.Divide(90, 100); //0.9
        decimal starty11 = Decimal.Multiply(height1, starty1); //1080
        decimal endy1 = Decimal.Divide(20, 100); //0.2
        decimal endy11 = Decimal.Multiply(height1, endy1);  //240
        decimal startx1 = Decimal.Divide(width1, 2); //360    

driver.Swipe(Convert.ToInt32(startx1), Convert.ToInt32(starty11), Convert.ToInt32(startx1), Convert.ToInt32(endy11), 5000);

For RIGHT TO LEFT SWAPPING USE THE BELOW C# CODE

        int height = driver.Manage().Window.Size.Height;  //1200            
        int width = driver.Manage().Window.Size.Width; //720


        decimal height1 = height; //1200
        decimal width1 = width; //720           
        decimal startx1 = Decimal.Divide(90, 100); //0.9
        decimal star_x = decimal.Multiply(width, startx1); //648
        decimal end_x1 = Decimal.Divide(90, 1000); //0.09
        decimal end_x = decimal.Multiply(width, end_x1); //64.8
        decimal star_y = decimal.Divide(height1, 2); //600

driver.Swipe(Convert.ToInt32(star_x), Convert.ToInt32(star_y), Convert.ToInt32(end_x), Convert.ToInt32(star_y), 5000);


#5

public void swiptToBottom()
{
Dimension dim = driver.manage().window().getSize();
int height = dim.getHeight();
int width = dim.getWidth();
int x = width/2;
int top_y = (int)(height0.80);
int bottom_y = (int)(height
0.20);
System.out.println(“coordinates :” + x + " "+ top_y + " "+ bottom_y);
TouchAction ts = new TouchAction(driver);
ts.press(x, top_y).moveTo(x, bottom_y).release().perform();
}

This will work awesome for swipe to bottom.