We are testing our app using appium automation for that we are trying to set accessiblity identifier for all the components which we are using in our app. But are facing an issue in setting the accessibility identifier for few components (UIPickerView,UIDatePicker). For these items we want to set the accessibility identifiers for the each subviews of the component. for ex: in UIPickerView Delegate Method viewforRow we are trying to set the accessibility identifier for each view. but while check for the accesssibility identifier in appium it is nil please help me out
Issue in setting the accessibility identifier for few components (UIPickerView,UIDatePicker)
Could you explain how you try to set these identifiers.
I suppose it is not in IB but directly in code ?
Could you show this part of code ?
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIView *customView = [UIView alloc]init];
self.isAccessibilityElement = NO;
self.shouldGroupAccessibilityChildren = YES;
customView.isAccessibilityElement = YES;
[customView setAccessibilityLabel:[NSString stringWithFormat:@"currCombo%ld",(long)row]];
[customView setAccessibilityIdentifier:[NSString stringWithFormat:@"currCombo%ld",(long)row]];
NSLog(@"iOS Automation Accessible ID : currCombo%ld",(long)row);
return customView;
}
I am using this code
when ever i tried to set the accessibility identifier it getting set to the accessibility value. Accessible identifier is always nil. please check the below screen shot
Could you show where you try to access the accessibility identifier ?
Note: your screenshot cannot show on the forum
I wrote the following (in Swift) that is very similar to what you wrote
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let customView : UIView = UIView(frame: CGRect(x: 0, y: 0, width : 100, height: 14))
var label : UILabel
self.isAccessibilityElement = false
self.shouldGroupAccessibilityChildren = true
customView.isAccessibilityElement = true
customView.accessibilityIdentifier = "The identifier" + String(row)
customView.accessibilityLabel = "The label" + String(row)
label = UILabel(frame: CGRect(x: 0, y: 0, width : 80, height: 12))
label.text = String(row)
customView.addSubview(label)
print(customView.accessibilityIdentifier!, customView.accessibilityLabel!)
return customView;
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("Selected", row, pickerView.view(forRow: row, forComponent: component)!.accessibilityIdentifier!)
}
And it works: when I select in picker, I get the accessibilityIdentifier printed:
Selected 2 The identifier2
The difference with yours, is
- I initalize the customView
let customView : UIView = UIView(frame: CGRect(x: 0, y: 0, width : 100, height: 14))
- I created a subview to hold a label for customView
Hi Clude
Thanks for reply.
You just open the Accessibility inspector from xcode and do an inspection for that picker view you will get the output as below
label : <nil>
Value : The identifier 0
Traits : Adjustable
Identifier : <nil>
We are doing Automation testing (appium).
So, Before doing didSelectRow at indexPath (Delegate Method) we need to set the accessibility identifier for each row in pickerView.
So, that this allowses automation to select the element based on its ids.
I don't understand:
You set accessibility in code, it is normal you do not get it in IB !
In addition, you specify in code
self.isAccessibilityElement = NO;
I understood you wanted to create accessibility indentifier for subviews, which are not declared in IB.
So, what is the point ?
So, Before doing didSelectRow at indexPath (Delegate Method) we need to set the accessibility identifier for each row in pickerView.
So, that this allowses automation to select the element based on its ids.
I don't think so, I did it in viewForRow and it works.
I just use it in didSelect to show that it was effectively set.
Can you take screen shot of Xcode Accessibility Inspector and share it. It will be useful for me.
I just sent a mail with a screenshot
Thanks for the screen shot clude
we can set Accessibility Identifier for the whole Picker Component.
But i want accessibility identifer for each inner subviews in the UIPicker wheel.
you just check the same in Accessible Inspector you will not get the Accessible identifier.
xcode -> open developer tool -> Accessible Inspector
I've never used this tool, so I cannot tell.
However, you can set identifier in code, as I proposed:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let customView : UIView = UIView(frame: CGRect(x: 0, y: 0, width : 100, height: 14))
var label : UILabel
self.isAccessibilityElement = false
self.shouldGroupAccessibilityChildren = true
customView.isAccessibilityElement = true
customView.accessibilityIdentifier = "The identifier" + String(row)
customView.accessibilityLabel = "The label" + String(row)
label = UILabel(frame: CGRect(x: 0, y: 0, width : 80, height: 12))
label.text = String(row)
customView.addSubview(label)
print(customView.accessibilityIdentifier!, customView.accessibilityLabel!)
return customView;
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("Selected", row, pickerView.view(forRow: row, forComponent: component)!.accessibilityIdentifier!)
}
Didn't this work for you ?
I am also facing this issue, i couldn't access Components in Picker, After adding accessible identifier in ViewForRow, still it's not reflecting in object hierarchy.
Please help with solution.
Where, in IB ? Elsewhere ?After adding accessible identifier in ViewForRow, still it's not reflecting in object hierarchy.
DataPicker not components inside to access in Appium.
<XCUIElementTypeOther name="datePicker">
I am also facing the same problem which you were discussing about.
Did the issue is resolved or Not?
Is that possible to set accessibility identifier for each row in Pickerview. ** can you please let me know if that Possible to Resolve if from our end OR Not Possible?**