SalmonKiller
SalmonKiller

Reputation: 2203

Swift - How to set the value of an XCUIElement

While trying to implement the new UI Testing in Swift, I tried to set the value of a text field by doing this:

app.textFields["field_name"].setValue(value, forKey: "any key")

However, I got an error saying that the key is not found.

So my question is:

a) Is there an easier way to do this?

an if not

b) How do I obtain the correct key so I can set the value of the text field?

Thanks

Upvotes: 0

Views: 3125

Answers (1)

Sulthan
Sulthan

Reputation: 130102

When you are UI testing, you don't usually just set values on objects, you are trying to replicate what the user is doing. In this case you probably want:

app.textFields["field_name"].typeText(value);

Upvotes: 4

Related Questions