【问题标题】:swipe actions in native apps using Appium-android使用 Appium-android 在本机应用程序中滑动操作
【发布时间】:2015-10-15 07:28:04
【问题描述】:

几天前我开始学习 appium。好吧,我的问题是我想在 Flipkart 应用程序中滑动图像并缩放图像。我已经尝试使用下面的代码,但是滑动操作是在同一页面上执行的,即在同一个图像上,它使用 x 轴和 y 轴线从右到左移动,没有执行缩放操作。谁能告诉我有关如何滑动图像和缩放它的 java 代码。

以下代码:

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);

【问题讨论】:

    标签: android appium


    【解决方案1】:

    您可以尝试使用 TouchAction 类执行滑动。

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

    【讨论】:

      【解决方案2】:

      您可以尝试使用这种和平代码为所有移动设备动态滑动:

      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;
      }
      

      【讨论】:

        猜你喜欢
        • 2014-06-13
        • 1970-01-01
        • 2020-11-04
        • 1970-01-01
        • 2017-02-07
        • 2016-02-26
        • 2020-02-20
        • 1970-01-01
        • 2021-06-13
        相关资源
        最近更新 更多