我試過scrollTo()使用andriod驅動程序滾動我的應用程序頁面,但沒有工作,因爲它已從javaclient 4.1.2棄用。如何使用Android驅動程序滾動頂部到底部
我已經通過下面的鏈接,但找不到任何解決方案。 How can I scroll an android app page from top to bottom using appium driver?
請提供給我的解決方案
我試過scrollTo()使用andriod驅動程序滾動我的應用程序頁面,但沒有工作,因爲它已從javaclient 4.1.2棄用。如何使用Android驅動程序滾動頂部到底部
我已經通過下面的鏈接,但找不到任何解決方案。 How can I scroll an android app page from top to bottom using appium driver?
請提供給我的解決方案
我的例子是蟒蛇,但它會爲Java的工作,以及只使用Java語法找到元素像
driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("**/Put some text which is at bottom of screen to scroll screen/**").instance(0))')
更多的細節,你可以去通的https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html和https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html
用戶揮動方法如下:
driver.swipe(startx, starty, endx, endy, duration);
例如向下滑動
driver.swipe(100, 100, 100, 900, 3000);
根據您可以更改x和y座標。
你可以試試這個下面的代碼,我在設置頁面上嘗試這種代碼..
AppiumDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap1);
driver.scrollTo("About phone");
傳遞字符串,它存在於你的應用程序頁面的底部。
driver.scrollTo("Enter your value");
使用適當的等待語句。
@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);
}
上面的例子使用垂直滾動,它是基於在這個博客給出了水平滾動http://qaautomated.blogspot.in/2016/02/how-to-do-horizontal-scroll-in-appium.html我希望這對你的作品的例子。
工作完美,做得很好 – bkapVT