2

So I have a custom UITextField that also has a floating label (using JVFloatLabeledTextField) that is in a custom view. In my custom view class I set the accessibility element to the JVFloatLabelTextField like so

CustomView.h

   
   self.textField.isAccessibilityElement = YES;
    self.textField.floatingLabel.isAccessibilityElement = YES;
//  CGRect textFieldFrame = self.textField.frame - self.textField.floatingLabel.frame;
    CGRect textFieldFrame = CGRectMake(0, self.textField.floatingLabel.frame.size.height, self.textField.frame.size.width, self.textField.frame.size.height - self.textField.floatingLabel.frame.size.height);
    textFieldElement.accessibilityFrame = [self convertRect:textFieldFrame toView:nil];
    textFieldElement.accessibilityIdentifier = @"TextField";
    textFieldElement.accessibilityLabel = @"text field";
    [self.accessibleElements addObject:textFieldElement];
In my UI Test class, I created a test to find the text field and it crashes on typeText. For some reason, it is not recognizing the textfield as a of XCUIElement type text field, instead it recognizes it as type other. Here I check if the element exists:

This element does NOT exist

    XCUIElement *textFieldElement = [[scrollViewQuery.otherElements matchingIdentifier:@"CustomView"] containingType:XCUIElementTypeTextField identifier:@"TextField"].element;

But this DOES exist:

XCUIElement *textFieldName = [scrollViewQuery.otherElements matchingIdentifier:@"CustomView"].otherElements[@"TextField"];

Does anyone know how I can get it to recognize the textfield as of XCUIElement type textfield??? Thank you!

Jenel Ejercito Myers
  • 2,553
  • 2
  • 16
  • 24
  • Why does it matter? You can still call `typeText:` on any `XCUIElement`, text field or not. – Joe Masilotti Dec 16 '16 at 11:29
  • @JoeMasilotti because it fails everytime I use typeText. I have turned off connect hardware keyboard and it still fails. I've narrowed it down to failing at that specific line. I see the keyboard, but right when it tries to type it fails – Jenel Ejercito Myers Dec 16 '16 at 18:30
  • Does the element have focus? You can inspect this with `Accessibility Inspector.app` on your Mac. – Joe Masilotti Dec 16 '16 at 22:09
  • Try adding the '[adjustable](https://developer.apple.com/reference/uikit/uiaccessibilitytraitadjustable)' accessibility trait to the view. – Oletha Dec 25 '16 at 01:45

0 Answers0