How do you access the text in a Navigation Bar for iOS?
Currently I can get the navigation bar IOSElement
with the following snippet:
IOSElement element = driver.findElementByClassName("XCUIElementTypeNavigationBar");
None of the methods on IOSElement
return the actual title of the navigation bar:
element.getText() // null
element.getTagName() // XCUIElementTypeNavigationBar
element.getId() // 0E4268B9-A13B-4BB4-958F-1092BFF73E23
I believe I found a suitable means to check the text with the following method.
public void verifyNavigationBarTitle(String title) {
List<IOSElement> elements = driver.findElementsByName(title);
boolean isDisplayingCorrectText = false;
for (IOSElement element : elements) {
if (element.getTagName().equals("XCUIElementTypeNavigationBar")) {
isDisplayingCorrectText = true;
}
}
if (isDisplayingCorrectText == false) {
System.out.format("Error: Navigation bar title does not display %s", title);
}
}