繁体   English   中英

无法从另一个本机应用程序的 Android 库中选择图像

[英]Unable to select image from Android gallery from another native app

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

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

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

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

我希望您正在尝试单击 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;

                }

            }
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM