0

I'm trying to automate an iOS app which was built using Pega PRPC. But i'm unable to find some elements.

Below is the elements section in appium,

Appium inspector view

Below is the code i used to refer that element,

private IOSDriver<MobileElement> driver;
URL url = new URL(configFileReader.getAppiumUrl());
driver = new IOSDriver<MobileElement>(url, cap);


MobileElement enterValueToHeadOnWeir = driver.findElementByClassName("XCUIElementTypeTextField");
enterValueToHeadOnWeir.sendKeys(configFileReader.getHeadOnWeirValue());

With the above code, i was able to get the element. But within the same screen I have same kind on text fields with the same className and it doesn't have any unique identifiers. For the first element this will work but i'm unable to work on other text fields.

As this is a PEGA App, i have "data-test-id" attribute for those elements, will i be able to use that with Appium?

cindy87
  • 47
  • 10

1 Answers1

2

If you have elements more than one with same specific, you can collect them in a list with .findelementsBy*:

List<MobileElement> enterValueToHeadOnWeir = driver.findElementsByClassName("XCUIElementTypeTextField");

//example to second element
enterValueToHeadOnWeir.get(1).sendKeys(configFileReader.getHeadOnWeirValue());

This is index of element: .get(1).

But if you want still using "data-test-id" you mean, you can achieve by xpath:

MobileElement enterValueToHeadOnWeir = driver.findElementByXPath("//*[@elementId='enter_value_here']");
enterValueToHeadOnWeir.sendKeys(configFileReader.getHeadOnWeirValue());
frianH
  • 7,295
  • 6
  • 20
  • 45
  • I used below code with data-test-id and it's giving me "NoSuchElementException" MobileElement enterValueToHeadOnWeir = driver.findElementByXPath("//input[contains(@data-test-id,'HeadOnWeir')]"); – cindy87 Nov 27 '19 at 04:41
  • @cindy87 With your above picture you haven't `data-test-id` attribute. Please follow the `xpath` in answer and put correct id number to change `enter_value_here`. – frianH Nov 27 '19 at 04:50
  • we also have a web view for this app, when i inspect the element from browser it shows data-test-id attribute. To use this attribute does it need to show in appium inspector as well? – cindy87 Nov 27 '19 at 21:07
  • @cindy87 If in appium inspector you can't see that attribute, you can't use it. – frianH Nov 28 '19 at 03:02
  • @cindy87 Try change `data-test-id` to `elementId`, like this answer. Or you have tried approach `List` ? – frianH Nov 28 '19 at 03:06
  • 1
    elementId is not static, it keeps changing due to that i used the List approach. Thanks a lot it's working fine now. – cindy87 Nov 28 '19 at 03:23