【问题标题】:Unable to select image from gallery in appium android无法从appium android中的图库中选择图像
【发布时间】:2018-08-31 21:16:36
【问题描述】:

我使用的是“java-client-5.0.4”版本,我无法从图库中选择图片。

这是我的代码

List<AndroidElement> galleryElements = driver.findElementsByClassName("android.widget.ImageView");
TouchAction t = new TouchAction(driver);
t.tap(galleryElements.get(0)).perform();

【问题讨论】:

    标签: appium appium-android


    【解决方案1】:

    在这种情况下,您可以使用资源 ID

    By selectPhoto = By.id("imageView");
    driver.findElement(selectPhoto).click();
    

    但是这里有个问题,它总是会选择第一张图片,对于特定的图片选择你应该使用xpath和索引

    【讨论】:

    • 所有图片都有相同的resource-id,这就是我使用class的原因,但它根本没有选择。
    【解决方案2】:

    使用 ArrayList 并获取该列表中的所有图像列表。之后提供数组列表的索引,您可以选择任何图像:

    ArrayList<WebElement> listImage=(ArrayList<WebElement>) driver.findElements(By.id("com.euradvance.classstars:id/image"));
    System.out.println(listImage.size());
    listImage.get(5).click();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多