2015-10-15 24 views
0

幾天前我開始學習appium。那麼,我的問題是我想在flipkart應用中滑動圖像並縮放圖像。我曾嘗試使用下面的代碼,但是滑動操作已在同一頁面上執行,即在同一圖像上,它從x軸和y軸線的右側移動到左側,縮放操作尚未執行。任何人都可以用java代碼告訴我如何滑動圖像並縮放它。使用Appium-android在原生應用中滑動操作

下面的代碼:

driver.findElement(By.className(properties.getProperty("cross_mark_className"))).click(); 
    System.out.println("clicked on cross mark"); 
    driver.findElement(By.className(properties.getProperty("home_menu_className"))).click(); 

    WebElement mobile = driver.scrollTo("Mobiles"); 
    System.out.println("scroll till Mobiles in home slider menu"); 
    mobile.click(); 
    driver.scrollTo("Top Offers!!").click(); 
    driver.scrollTo("Honor 4x").click(); 
    delay(4000); 
    WebElement honor = driver.findElementById("com.flipkart.android:id/product_list_product_item_image"); 
    taction.tap(honor); 

driver.swipe(495,484, 52, 484, 12000); 
delay(12000); 
driver.zoom(honor); 
delay(8000); 

回答

0

你可以嘗試使用TouchAction類進行刷卡。

TouchAction action = new TouchAction(driver).longPress(x,y).moveTo(x, y).release(); 
action.perform(); 
0

你可以用這個和平的動態刷卡代碼爲所有的移動設備的嘗試:

Dimension dimension = driver.manage().window().getSize(); 
int width = dimension.getWidth(); 
int height = dimension.getHeight(); 
switch(direction) 
{ 
case "right" : driver.swipe((int) (width*(0.20)), (int) (height*(0.50)), (int) (width*(0.80)), (int) (height*(0.50)), 6000); 
break; 
case "left" : driver.swipe((int) (width*(0.80)), (int) (height*(0.50)), (int) (width*(0.20)), (int) (height*(0.50)), 6000); 
break; 
case "up" : driver.swipe((int) (width*(0.50)), (int) (height*(0.70)), (int) (width*(0.50)), (int) (height*(0.30)), 6000); 
break; 
default : driver.swipe((int) (width*(0.50)), (int) (height*(0.30)), (int) (width*(0.50)), (int) (height*(0.70)), 6000); 
break; 
}