Scroll till end of the page using appium-android

无人久伴 提交于 2020-01-13 18:25:07

问题


For a hybrid app , I need to scroll till the end of the page. How can I do ? I am able to scroll to exact element by using driver.scrollTo(); and driver.ScrollToExact();

But I want to scroll the app from top to bottom. Can anyone tell me please?


回答1:


 @Test
    public void testScroll()throws Exception
    {
        for(int i=0;i<4;i++)
        {
            Thread.sleep(2000);
            if (driver.findElement(By.name("end_item")).isDisplayed())
            {
                driver.findElement(By.name("end_item")).click();
                break;
            }
            else
            {
                verticalScroll();
            }

        }
    }
    public void verticalScroll()
    {
        size=driver.manage().window().getSize();
        int y_start=(int)(size.height*0.60);
        int y_end=(int)(size.height*0.30);
        int x=size.width/2;
        driver.swipe(x,y_start,x,y_end,4000);
    }

This will help you to swipe till end or till whatever position you want.




回答2:


You can use coordinates to scroll to the end of the page with even locating the String available on the page. Use this:

TouchAction action = new TouchAction(driver).longPress(20,y).moveTo(20, 10).release();
action.perform();



回答3:


I too had the same problem. What I did is, used the text which is at the bottom of that particular page ("text should be dynamic, it should be constant") then used the following code

String text="ABC";
driver.scrollTo(text);

After this code you can perform any action.. for example see the below code

String text="ABC";
driver.scrollTo(text);  
driver.findElement(By.xpath("//*[@text='"+text+"']")).click();


来源:https://stackoverflow.com/questions/33212411/scroll-till-end-of-the-page-using-appium-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!