Search code examples
appium

How to write xpath if two text field having same class name in appium 1.7.for ios


Can anyone help me to write xpath in appium 1.7 for iOS..

If two class having same name

driver.findElementByClassName("TextField").sendKeys("abc");
driver.findElementByClassName("TextField").sendKeys("1234");

Solution

  • In any case use className is not reliable search strategy as its not a unique.

    I usually suggest following rules:

    • have unique AccessibilityId for most of elements used in automation tests (talk with developers if they agree to fix this)
    • If not, build unique Xpath with relation to other elements that have AccessibilityId or more unique className

    As a temporary solution you can do this:

    List<WebElement> textfields = driver.findElementsByClassName("TextField");
    textFields.get(0).sendKeys("abc");
    textFields.get(1).sendKeys("1234");
    

    since you didn't provide your page source, better print it out with driver.getPageSource() and think of good XPath that you put in:

    List<WebElement> textfields = driver.findElementsByXpath(<your xpath>);