Unable to get 'UIATableCell' count of 'UIATableView' in iOS

Hello bhaskar,

The below code works for me.

if (driver.findelement(tableview xcpath)!=null) {
int size = driver.findelement(tableview xcpath).findElementsByClassName(“UIATableCell”).size();
System.out.println(“The size”+size);
for (int i=0;i<=size;i++){
row = driver.findelement(tableview xcpath).findElementsByClassName(“UIATableCell”).get(i);
String name = driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell["+i+1+"]/UIAStaticText[2]")).getText();
}
}

1 Like

Hi Telmo,

I am using iOS native app to automate. I have a table with rows and each rows does not have a column. But The columns need to be split based on space. When I split columns it is creating issue. Let me show you how it looks

Please let me know if there any solution for this. I cannot split based on space because second column data has a space and this creates problem.

Regards
AJ

Well, you can try:

String[] arrayStrings = yourRow.split(" ")

arrayStrings[0] will be the first column
arrayStrings[arrayStrings.size()-1]  will be the last column
arrayStrings[arrayStrings.size()-2]  will be the last -1 column

and so on until you get last 5 elements. The rest of strings (you can know them knowing the .size() - 5 and less the first one) are the second column

Hi telmo

I tried the same approach here but the thing is second column which has “Click & Collect” and "Standard Delivery " also get split and every row will give different column count and this is causing the issue.

Any concrete solution for this?

My solution works for you :slight_smile:

Try this horrible piece of code:

class Appium {
    public static void main(String args[]) {
        String finalValues[] = new String[7];
        String yourRow = "10086628 Standard ui Delivery Open L2 1 1 0";
        String[] arrayStrings = yourRow.split(" ");
        finalValues[0] = arrayStrings[0];

        int incr=1;
        for (int i=(finalValues.length-1);i>1;i--) {
            finalValues[i] = arrayStrings[arrayStrings.length-incr];
            incr++;
        }

        finalValues[1] = "";
        while (incr<arrayStrings.length) {
            finalValues[1] = arrayStrings[arrayStrings.length - incr]+ " " + finalValues[1];
            incr++;
        }

        //print result
        for (int i=0;i<finalValues.length;i++) {
            System.out.println("Column "+(i+1)+": "+finalValues[i]);
        }
    }
}

That will result in:

Column 1: 10086628
Column 2: Standard ui Delivery 
Column 3: Open
Column 4: L2
Column 5: 1
Column 6: 1
Column 7: 0
1 Like

Hi Telmo, thank you so all your solutions. it is working fine for me.

I am facing one more problem. When I want to validate whether the data is value1 or value 2 I am unable to run it.
here is the below code and unfortunately expect is not working here. I am not sure what is the issue here

totalRows=batchlistPage.getRowCount
rowNum=1
while(rowNum<=totalRows)
data = batchlistPage.getRowText(rowNum)
puts data[3]
puts value1
puts value2
expect(data[3]).to eq(value1) | eq(value2)
//ABOVE LINE IS NOT EXECUTING AND IT COMES UP WITH FAIL MESSAGE
# expect(data[3].to eql? value1 || (data[3].to eql? value2)

  rowNum+=1
  end

This code worked for me actually. Thanx

hi
Below code is working for me ,
int size=driver.findElement(By.xpath(“here specify your xpath fo UIATable”).findElements( By.className(“UIATableCell”)).size();

Try that code .

Hi Madhumita,

I tried your code but it’s not working for me. Saying Cast is redundant. How did you implement it :slight_smile: