无法从其他本机应用程序从Android图库中选择图像

时间:2019-02-12 19:42:43

标签: java selenium automation appium

需要通过另一个本机应用程序从图库中选择图像,但无法选择该图像。

  

单击添加图像(在本机应用程序上)->从库->所有图像->选择实际图像

代码的工作部分::单击“添加图像”(在本机应用程序上)->“从库”->“所有图像”

//Click Add Photo icon in the app to select an image from gallery

wait.until(ExpectedConditions.elementToBeClickable(iconAddPhoto));
        iconAddPhoto.click();   

//Select from Library option when Take Photo/Choose from Library Option is shown
        wait.until(ExpectedConditions.visibilityOf(lnkChooseFromLibrary));
        lnkChooseFromLibrary.click();

//Select All Pictures folder when All Pictures and Whatsapp Image folders are displayed
        List<MobileElement> galleryElements = 
driver.findElements(By.className("android.widget.ImageView"));
        galleryElements.get(0).click();

代码不起作用:从“所有图片”文件夹中选择实际图像

//Tried the below combinations one at a time to select the actual image but the element is not getting detected

driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'com.ebay.kijiji.ca:id/grid_item_image')]")).click();

driver.findElement(By.xpath("//android.widget.ImageView[contains(@resource-id,'com.ebay.kijiji.ca:id/grid_item_image')]")).get(0).click();

AndroidElement abc = (AndroidElement) driver.findElement(By.xpath ("//android.widget.ImageButton[@bounds='[4,210][238,410]']"));
        abc.click();

List<MobileElement> galleryElements1 = driver.findElements(By.id("com.ebay.kijiji.ca:id/image_library_grid"));
        galleryElements1.get(0).click();

ArrayList<MobileElement> listImage=(ArrayList<MobileElement>) driver.findElements(By.id("com.ebay.kijiji.ca:id/image_library_grid"));
        System.out.println(listImage.size());
        listImage.get(5).click();

1 个答案:

答案 0 :(得分:0)

我希望您尝试单击在Grid中显示的照片。

最初,由于appium从网格底部选择了元素,因此尝试在相册的网格中减少照片。

    public void selectPhotos(int numberOfPhotos){

            //Find the grid element
            WebElement gridAlbum= driver.findElement(By.xpath("xpath of the full grid of album"));

            //Add the rows of element to the list
            List<WebElement> gridRows=gridAlbum.findElements(driver.findElement(By.xpath("xpath of the row element");

           //find the number of rows
            System.out.println("Number of Rows"+gridRows.size());

            for(WebElement row:gridRows) {

                List<WebElement> cells=row.findElements(driver.findElement(By.xpath("xpath of the element");

                for(WebElement cell:cells) {

                    if(count>0) {
                    cell.click();
                    count--;
                    }
                    else
                      break;

                }

            }
        }