@iOSXCUITFindBy Annotations don't work but the same code works when I use driver.findElement(By.accessibilityid) or even xpath


#1

My code -
public class HomePage {

Data data;
String dataFile;
public IOSDriver<IOSElement> driver;

public HomePage(IOSDriver<IOSElement> driver, String dataFile) throws JsonParseException, JsonMappingException, IOException, InterruptedException {
	this.data = Data.get(dataFile);
	this.dataFile=dataFile;
	this.driver=driver;
	PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}

Tried with accessibility -
@iOSXCUITFindBy (accessibility = “Jio Welcome Polys”)
private IOSElement welcomeBanner;

Tried with xpath - 

@iOSXCUITFindBy (xpath = "//XCUIElementTypeImage[@name='Jio Welcome Polys']")	
private IOSElement welcomeBanner;

Assert.assertTrue(welcomeBanner.isDisplayed());

None of the annotations work ^^ -
Error thrown - Can’t locate an element by this strategy: By.chained({By.AccessibilityId:
java-client : 7.0.0

It works when i use -
driver.findElementByXPath("//XCUIElementTypeImage[@name=‘Jio Welcome Polys’]").isDisplayed();


#2

With annotation instead of accessibility try “id”


#3

I had the same issue and found the solution:
add the following capability to your driver initialization:
capabilities.setCapability("automationName", "XCUITest")

I think you have to add that in your “dataFile” in the right format.

Explanation here:
http://appium.io/docs/en/drivers/ios-xcuitest/index.html