问题
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