nooby
nooby

Reputation: 85

Getting all the UI elements of the current screen in UI testing or Unit tests

I am new to iOS and writing a UI test case for a screen. The thing is, I want to write such a test case where I want to test same behavior for a particular type of UIElement (for eg, same behavior for button type). So instead of writing tests for different screens I wanted to know if there's some way in XCUI or any other framework where we can get all UIElements present on the screen in some data structure. Thanks

Upvotes: 2

Views: 1446

Answers (1)

Roman Zakharov
Roman Zakharov

Reputation: 2273

You can get such data (elements, their labels, types, and other properties) with snapshot() method. You will get a tree of XCUIElementSnapshot. Also, you can get a dictionary representation.

Start reading documentation from here

https://developer.apple.com/documentation/xctest/xcuielementsnapshotproviding

Upvotes: 2

Related Questions