【问题标题】:NoSuchElementException : Unable to select image from galleryNoSuchElementException:无法从图库中选择图像
【发布时间】:2016-05-17 11:00:59
【问题描述】:

我正在使用 nexus 5 进行测试。如何在 Android 中使用 appium 从图库中选择图像。当我使用以下代码时:

driver.findElement(By.xpath("//android.widget.ImageView[@content-desc='Photo
    taken on 13 May 2016 12.50']")).click();

我遇到了这样的异常:

Exception in thread "main"
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING:The
server did not provide any stacktrace information) Command duration
or timeout: 50.56 seconds

【问题讨论】:

    标签: appium nosuchelementexception


    【解决方案1】:

    试试这个:

    driver.findElement(By.xpath("//*[@class='android.widget.ImageView' and @content-desc='Photo taken on 13 May 2016 12.50']")).click();
    

    【讨论】:

      【解决方案2】:

      尝试用这种方式编写它只会选择第一个:

        driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'id of your image')]")).click();
      

      使用此代码,您可以选择您想要放置的任何元素,而不是 i 您想要从 0 开始的第一个元素:

      driver.findElements(By.xpath("//android.widget.ImageView[contains(@resource-id,‌​'id of your image')]")).get(i).click();
      

      【讨论】:

      • Emma 感谢代码对我有用,但唯一的问题是它只选择第一张图片
      • 欢迎,为此感到高兴;)(我是 Emna,不是 Emma,哈哈)
      • 我有一个很酷的想法让你选择任何元素,尝试编译这段代码,而不是我放任何你想要的元素,例如当 i = 0 它是第一个元素:driver.findElements(By.xpath("//android.widget.ImageView[contains(@resource-id,'id of your image')]")).get(i).click();
      • 抱歉拼写错误。
      • 没问题,你试过第二个吗?
      【解决方案3】:

      最好的方法是创建 xpath!

       find_element(xpath: "//android.widget.FrameLayout[1]").click
      

      如果不同,请相应更改您的班级名称。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-31
        • 2012-08-01
        • 1970-01-01
        相关资源
        最近更新 更多