How to get the value of textfield
in XCODE7 UITesting?
var b = XCUIApplication().childrenMatchingType(.textField).elementBoundByIndex(0).stringValue
Let's suppose you have a Text Field like so:
(I'm hardcoding it's value there ("My Text") for the sake of the example.)
Give it an Accessibility Label
. In this case, I'm giving it the "Text Field" label.
Now to access its value, you could do something like:
func testExample() {
let app = XCUIApplication()
let textField = app.textFields["Text Field"]
XCTAssertTrue(textField.value as! String == "My Text")
// So basically "textField.value"
}
On a side note: when in doubt on how to access certain properties of a given XCUIElement
, I found that its debugDescription helps a lot.
For example, set a breakpoint after the property declaration, execute the test, wait for the app to stop at the breakpoint, go to lldb console
, type po propertyName.debugDescription
, and check the output:
I hope that helps.