Search by xpath with parameters is not working in iOS8 simulator

I’m testing native app. with TableView and TableCells
in iOS7 construction like //UIATableCell[contains(@value, ‘11111’)] is working fine, but not in iOS8.
appium 1.4.8

cause tables have different structures in iOS7 and iOS8.

in code the only solution we made is work differently depending on version.

Example:

public int getNumberOfVisibleMessagesInList(String deviceName, String osVersion) {
        int size;
        if(deviceName.contains("iPhone")) {
            if(osVersion.equals("7.1"))
                size = messageInList_iPhone.size()/2;
            else
                size = messageInList_iPhone.size();
        } else if (deviceName.contains("iPad")) {
            if(osVersion.equals("7.1"))
                size = messageInList_iPad.size()/2;
            else
                size = messageInList_iPad.size();
        } else {
            size = -1;
        }
        System.out.println("   messages list size: "+size);
        return size;
    }
1 Like

Not sure that I’ve got it how it should help me

in iOS7 it is //UIATableCell[contains(@value, ‘11111’)]
in iOS8 it will be like: //UIATableCell/UIAStaticText/[contains(@value, ‘11111’)]

just open your client in Appium Inspector or any iOS inspector to see the difference.

This solution is working, thx a lot.

@Aleksei Please guide

I am bit hands on in iOS I have a question here If we use classname then will that work over iOS version also something like as class name will always be same what ever table structure will be ???

List UIATableCell = driver.findElements(By.className(“UIATableCell”));
for (int i=0;i<UIATableCell.size()-1;i++) {
UIATableCell .get(i).findElements(By.className(“UIAStaticText”));
List UIAStaticText = UIATableCell.get(i).findElements(By.className(“UIAStaticText”));
for (int j=0;j<UIAStaticText.size()-1;j++){
if (UIAStaticText.get(j).getText().equals(“11111”)){
// TO DO CODE
break;
}
}

note : unable to put “{” for first FOR loop in above consider it while read code.

not clear what you expecting to test/check…

@Aleksei
I am really sorry about that !!! Actually I am asking that with changes to iOS version we see what you mentioned below, i.e. XPath changed locator fails we need to fire xpath based on iOS version

in iOS7 it is //UIATableCell[contains(@value, ‘11111’)]
in iOS8 it will be like: //UIATableCell/UIAStaticText/[contains(@value, ‘11111’)]

Why not If we write loop based on class name that should work in both iOS version 7 and 8 both as it is based on className’s and not on XPATH strategy…

So if we say content-desc/value of a node is “11111” we need to perform some action on that so the code I shared will that work on both platforms or not because it is dependent on classNames [UIATableCell and UIAStaticText] that remains same in both iOS versions

// get elements of UITableCell class
List UIATableCell = driver.findElements(By.className(“UIATableCell”));
for (int i=0;i UIATableCell .get(i).findElements(By.className(“UIAStaticText”));

// with in UITableCell get elements of UIStaticText class
List UIAStaticText = UIATableCell.get(i).findElements(By.className(“UIAStaticText”));

// Loop to see if our text is there , if found break loop
for (int j=0;j if (UIAStaticText.get(j).getText().equals(“11111”)){
// TO DO CODE
break;
}
}

note : unable to put “{” for first FOR loop in above consider it while read code

cause loop takes long time. it is seconds in one test but many minutes with test suite.

even “xpath” it self takes much more time to find instead of accessibility_ID strategy. We never(or few times) use it (xpath) with our tests which lasting for hours.

we have general time of 40-50sec per test from the moment of start driver to moment of close driver.

1 Like

In any case you can check XPATH expression that you are written in advance by online XPATH testers , like http://www.freeformatter.com/xpath-tester.html

For example i’ve used

public static void scrollToElement(IOSDriver driver,String elementName) {
	String targetCell = "//UIATableCell[UIAStaticText[@name=\""+elementName+"\"]]";
	WebElement cellWithText = driver.findElementByXPath(targetCell);
	HashMap<String, String> scrollObject = new HashMap<String, String>();
	scrollObject.put("element", ((RemoteWebElement)cellWithText).getId());
	driver.executeScript("mobile: scrollTo",scrollObject);
}