XCUIElement.exists fails when element is offscreen

37 Views Asked by At

I have an XCUITest that selects a file from the Files app. When the file is offscreen and needs to be scrolled to, 'exists' evaluates to false. When I scroll the screen to make the element visible, then 'exists' evaluates to true.

I'm running Xcode 15.

In other posts I've read through, it looks like 'exists' should be true when the element is on the screen and in the hierarchy even if the element is not visible at that moment and needs to be scrolled to...

Both of these ways of referencing the element operate similarly:

app.cells.matching(identifier: fileIdentifier).firstMatch.exists

app.otherElements.matching(identifier: fileIdentifier).firstMatch.exists

Does anyone know how to test for existence of offscreen elements? Or is this a bug?

1

There are 1 best solutions below

0
On

It depends on how the view is populated. In the instance of Files.app, I suspect they do not preload everything on initial load as that may be resource intensive. In such cases, the element will not exist until some amount of swiping has triggered it to be loaded. I suspect that’s what you’re seeing.