简体   繁体   中英

Not able to find element in pop up in appium

屏幕截图

In my app profile I want to select Religion, so when I am clicking on Religion one pop up is opening and I have to choose one element from there, Only "Index" and "text" values are different for each element, "Id" same for all element.

  1. But while taking "xpath" using "text" and "index" values, not getting the element.

  2. I am using scroll to method also but not getting the element.

Thanks in advance.

get all the index and its corresponding religions and click by index number

List<WebElement> ls = driver.findElementsById("android:id/numberpicker_input");             
System.out.println("no of religions" + ls.size());              
ls.get(0).click

You can click by using click method:

driver.findElementByName("your religion name").click();

and scroll by using this method:

public void keepScrollingUntilElementFound(String name) {
        for (int i = 0; i < 10; i++) {
            if (isElementPresent("name=" + name)) {
                break;
            } else {
                scrollDown();
                scrollDown();
            }
        }
    }



 public void scrollDown() {
        Dimension size = driver.manage().window().getSize();
        int x = size.width / 2;
        int starty = (int) (size.height * 0.60);
        int endy = (int) (size.height * 0.10);
        driver.swipe(x, starty, x, endy, 2000);
    }



 public boolean isElementPresent(String name) {
        try {
            driver.findElementByName(name);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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