How to print all the staticTexts in XCUITest

xcuitest cheat sheet
xcuitest print hierarchy
xcuitest best practices
xcuitest find element by identifier
xcuielementquery
xcuitest find element by label
nspredicate xcuitest
xcuiapplication statictexts

I have used app.staticTexts["String"].tap() to tap on a button containing that string which is working completely fine. But the problem here is that i want to print all the static texts which are present on that page, how can i do it in XCUITest ? My aim here is to iterate through all the static texts present on the page and then add an if condition on my expected text.

You can use something like that:

    for staticText in app.staticTexts.allElementsBoundByIndex {
        if staticText.label == "test" {

        }
    }

staticTexts, To receive the latest developer news, visit and subscribe to our News and Updates. Copyright � 2020 Apple Inc. All rights reserved. Terms of Use Privacy Policy� This is the command to print all the UI elements appearing in the string. As we can see, there's a lot of things in the UI at the moment — all the buttons, all the text fields. If you want to just print all the buttons, so we can XCUITest "buttons" so that will print only buttons in the view.

I suppose the text is present in the identifier attribute of the staticText element. You can try the following

for i in 0..<app.staticTexts.count {
    let text = app.staticTexts.element(boundBy: i).identifier
    print(text)
    if text == "Your String" {
        // Your code
    }
}

UI Testing: UILabel, debugDescription of the staticTexts and can find no useful properties. I tryed . value, .textFields, . String) nil (lldb) p print(app.otherElements["MainDisplay"]. For example, if you have — XCUIApplication().StaticTexts — we have multiple StaticTexts here and we have a label as well. If you don't have identifier then what you can do is if want to get the first or second StaticText, you can access as an other element.

//Returns all the labels,buttons, textfield,images in the page with its  name.
//Just change the element name in loop according to the need.




 for staticText in  app.staticTexts.allElementsBoundByIndex{

            if staticText != nil{
                print(staticText.label)
            }else{
                print("No static text found")
            }

        }

UI Testing Quick Guide, staticTexts["stateLabel"] startButton.tap() Print Element subtree. If your writing your tests manually (without recording) try printing the the element Find all buttons let buttonQuery = app.descendants(matching: .button)� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information

Xcode UI Testing Cheat Sheet – Hacking with Swift, staticTexts.element app.switches.element app. app.buttons.element // the button titled "Help" app.buttons["Help"] // all buttons inside a specific� XCTAssertEqual(app.buttons.element.title, "Buy") XCTAssertEqual(app.staticTexts.element.label, "test") There are two things that might catch you out. First, percentages for things like progress indicators are reported as strings with “%” attached. So, to check them you might write code like this:

Some good practices for XCUITest. Make it easier to add more , XCTAssert(viewExists)XCTAssert(app.staticTexts[“Result for Xcode term”].exists). A great practice is to identify each UIViewController's view,� @NSCopying var staticTexts: XCUIElement Query { get} See Also. Descendant Element Queries. var activity Indicators: XCUIElement Query. Required. var alerts

The Basics of XCUITest and Using Xcode UI Test Recorder, What is XCUITest and how are UI tests done with Xcode for iOS app testing? The UI The record-and-playback tools provide quickly all details about the application's UI layers, components and staticTexts[@"Master"] tap]; [editButton tap];. Hi I want to print in the screen only the fields of some of the data that is in the structure, Doom3 like: the name for example, or the field time in FIFA, or the field memory in word

Comments
  • you can try to find all accessibility elemtns and iterate, check XCUIElementQuery. But what you want to do looks more like unit test than UITest,
  • @Lu_ I actually want to iterate through all the static texts present on the page and then i would be adding a if condition on the expected text. So how can i perform that
  • Its printing "Find the StaticText" string for every loop, though i want the staticText value
  • Instead of identifier, try with value, label, or title