Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI XCTest, elements which exist in view

I am new to UI test writing.

I wanted to know if it is possible to know what elements are/exists in view. I want to know how many and how they are called.

I tried something like this to loop through all elements, but it does not work.

for element in app.accessibilityElements! {
        print(element)
    }
like image 575
Konrāds Bušs Avatar asked Dec 08 '22 22:12

Konrāds Bušs


1 Answers

You're looking for the debugDescription method of XCUIElement, in your case to get the entire hierarchy of the current visible window:

app.debugDescription

Quoting header comments:

Provides debugging information about the element. The data in the string will vary based on the time at which it is captured, but it may include any of the following as well as additional data:

   • Values for the elements attributes.
   • The entire tree of descendants rooted at the element.
   • The element's query.

This data should be used for debugging only - depending on any of the data as part of a test is unsupported.

like image 98
Tomas Camin Avatar answered Dec 11 '22 09:12

Tomas Camin