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

Hi Friends,

I am trying to get count/size of ‘UIATableCell’ from ‘UIATableView’ in iOS real device.

Can anyone help me …

Well, without any more details, its hard, but I’ll risk that this is what you want:

find_elements(:uiautomation,'.tableViews()[0].cells()').size
1 Like

Thq for the reply friend

This is the xpath of tableview : wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]

This is the xpath of tablecell: wd.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]

I am trying to get the count/size of TableCells in TableView.

1 Like

have you tried my answer? Its in ruby, but easily adapted to any client you use

I am working on Java because I don’t know Ruby…

Then something along this lines, maybe??

List<WebElement> elements = driver.findElementByIosUIAutomation(".tableViews()[0].cells()");

I’m not using java, but just explore this.

Hi Friend,

This code is not working…

Here’s what I do in python.

       table = self.driver.find_element_by_xpath(table_xpath)
       cells = table.find_elements_by_class_name('UIATableCell')

You can add a check for cells being empty if needed. And then stick that in a general function you can reuse throughout your framework.

Some other gotchas. In my AUT errors or other messages may be displayed in a UIATableCell in the UIATable, thus the function would return 1 cell, I’d try to extract expected data, and it would fail since the expected data was not present but some message was instead.

Thx Friend,

But I am looking for Java code…

I’ve given you the logic you can use: Find the table, using find_elements_by_class_name find all of it’s cell children. You simply need to rewrite it in Java.

1 Like

All answers are relevant but for your specific requirement try this code

List WebElement elements= driver.findElementsByXPath("//UIATableCell")
elements.size() ----> this will give you the count.

Had to skip <> in the above ex. coz the editor is skipping anything that is between < and >. First post on Appium forum :slight_smile:

Thanks Kiran,

I will try this code and let you know…

I am using the below code, but I am not getting correct cells in CollectionView

List elements1 = wd.findElements(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell"));
int numCells1 = elements1.size();

If there are 2 cells, I am getting output as 1 cell.

What is the page source XML?

Sorry I didn’t get you Graham.

Step1: Get the page source for the application you’re testing by opening the Appium Inspector and clicking the “Copy XML” button.
Step2: Open this online XPATH tester tool: http://www.freeformatter.com/xpath-tester.html and paste your page source XML into the “XML Input” section of the tool.
Step3: Paste your XPATH expression //UIAApplication[1]/UIAWindow[1]/UIACollectionView[1]/UIACollectionCell into “XPath expression” section of the tool.
Step4: Click the “Text XPATH” button to see the results of your proposed XPATH search

This is a much faster way of developing successful XPATH than running your test scripts over-and-over. It will show you which elements match your XPATH expression. It will describe any gross errors you’re experiencing, like an inability to compile your XPATH expression (not your current issue). And will help you learn how to visually parse the XML for data and relationships, which will further help you develop your XPATH skills.

I have several UIAStaticText Elements under each UIATableCell.

Can u tell me how i can iterate through the each of the TableCell and retrieve all the UIAStaticText

One solution in Python:

# Find your table, xpath in this example, use whatever locator strategy you want
table = self.driver.find_element_by_xpath(table_xpath)
# Find cells which are children of the table, note Appium doesn't support xpath for the children
cells = table.find_elements_by_class_name('UIATableCell')
# Iterate through the cells and obtain their text
for cell in cells:
	# Find text elements which are children of the cell, note Appium doesn't support xpath for the children
	current_cell_texts = cell.find_elements_by_class_name('UIAStaticText')
	# Do something with the text elements, store them, iterate through them, etc.

Hi,

i tried this…it worked…
List tableCells = (List) driver.findElementsByXPath("//UIAWindow[1]/UIATableView[3]/UIATableCell[@visible =‘true’]");
for(int i=0;i<tableCells.size();i++)
{
elementInTableCells = tableCells.get(i).findElements(By.xpath("//UIAStaticText"));
}

Hi Telmo,

I am facing an issue for validating a table row contents

I want to validate whether the value in a column are in ascending or descending order.

Could you please let me know how to do it? I am new to Ruby and using Ruby Capybara.