How do I check a cell is visible in a table view with Xcode 7 UI Testing?
Asked Answered
V

4

8

I have a table view with a lot of cells and not every cell is visible on a screen. When I check with

table.cells.staticTexts.matchingIdentifier("My Cell").element.exists

It returns true but the cell is not visible on the screen and I cannot tap on it. Because whenever I tap on it, a test fails.

How to check if an element is visible on a screen? Or how to tap on an element that is not visible?

Viaticum answered 3/9, 2015 at 10:27 Comment(1)
Here is my solution to this problem - hope it helps https://mcmap.net/q/799610/-uitesting-xcode-7-how-to-tell-if-xcuielement-is-visiblePostdiluvian
P
9

Use the hittable property instead of exists.

The class reference for XCUIElement explains that the hittable property will only return true if the element can be touched.

table.cells.staticTexts.matchingIdentifier("My Cell").element.hittable
Professoriate answered 16/2, 2016 at 11:4 Comment(0)
A
0

Instead of using element.exists try using element.hittable. This has worked for me, exists returns true if the element is currently in display hierarchy even though it is outside the screen view. hittable returns true only if the element is on screen and its hittable.

Abb answered 9/2, 2016 at 0:19 Comment(0)
M
0

The tableview method cellForRowAtIndexPath (NOT the delegate method of the same name) will return the cell at some index path if it is currently being displayed, or nil if it is not displayed.

If the user clicks on a button (or if anything happens with any view in your cell), you can also go up the view hierarchy to first find the cell, then the table view, and the method indexPathForCell will give you the index path of the cell.

Mosher answered 16/2, 2016 at 11:11 Comment(0)
S
0

you can use swipeUp method to scroll down until specific cell will be visible. You can also check that cell exist or not. something like this.

XCUIElementQuery *tableQuery = app.tables;
 if (!tablesQuery.cells.staticText[@"some text"].exist){
  [tablesQuery.staticTexts[@"visible cell text"] swipeUp];
}
Silas answered 20/4, 2016 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.