ioscocoa-touchtestingkif-frameworkkif

KIF 2.0 access element in UIWebview


Can somebody tell me how to access an input field in a uiwebview in KIF 2.0? Unfortunately I can't find anything on KIF Framework Github, neither in the documentation nor in the examples. I tried to access the input field via its id but this doesn't seem to work:

[tester tapViewWithAccessibilityLabel:@"username"];.

Thanks in advance. And if you have some nice resources about KIF 2.0 I would be happy if you send them to me.


Solution

  • In general, HTML text fields get their accessibility label from <label> tags. For example:

    <label for=myField>My Field</label> <input id=myField>
    

    In VoiceOver, this reads as a static text block "My Field", and a text field "My Field, Text Field, Double tap to edit." Both in VoiceOver and regular phone use, tapping the <label> will cause the text field to focus.

    If you call [tester tapViewWithAccessibilityLabel:@"My Field"], KIF will send a tap event to the label, causing UIWebView to focus the text field. You can then use [tester enterTextIntoFirstResponder:@"..."] to enter your text.