Search code examples
objective-cxcode-ui-testing

How can i clean the XCUIElement which type is textField?


XCUIElement *textField = app.textFields[@"xxxxx"];
[textField tap];
[textField typeText:@"12345678910"];
XCUIElement *key = app.keys[@"xx"]; (the "xx" is delete key)
    for (int a=0; a<11; a++) {
        [key tap];
    }

What i want to achieve is

textfield.text = @""

This method is too slow.


Solution

  • I am using this helper function:

    -(void)clearField:(XCUIElement *)textField {
        [textField doubleTap];
        [app.menuItems[@"Select All"]tap];
    }
    

    and calling it via:

    [self clearField: app.textFields[@"Last Name"]];