Element identification is failing with PageFactory

Dear Experts,

Can you identify the source of the error in this case?
Click works for:
iosDriver.findElement(AppiumBy.accessibilityId("Switches")).click();
But when @iOSXCUITFindBy Annotations is used then it fails with org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

Below is the Click call made to Dashboard screen
new Dashboard(iosDriver).clickOnSwitches();

Dashboard screen class-
package com.example.pages.ios;

import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.WebElement;
import io.appium.java_client.pagefactory.iOSXCUITFindBy;
import org.openqa.selenium.support.PageFactory;

public class Dashboard{
    private IOSDriver driver;
    public Dashboard(IOSDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }
    /**
     * Locators
     */
    @iOSXCUITFindBy(id = "Switches")
    private WebElement switches;

    public void clickOnSwitches() {
        switches.click();
    }
}

----> update to

PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(sec)), this);
1 Like

After using
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(sec)), this);
…its now throwing below error:

java.lang.ExceptionInInitializerError
	at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:53)
	at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
	at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:208)
	at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$000(AppiumFieldDecorator.java:60)
	at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:99)
	at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:63)
	at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:146)
	at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:111)
	at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:103)
	at com.example.pages.ios.Dashboard.<init>(Dashboard.java:16)

I try using

@iOSXCUITFindBy(accessibility = "Switches")
private WebElement switches;

But still getting NoSuchElementException on switches.click();

public void clickOnSwitches() {
   switches.click();
}

your Java version tooooooo high. Move to e.g. 11. This is Java + Selenium issue

1 Like
1 Like

Great suggestions! @Aleksei @mykola-mokhnach

JVM Argument setter

Using AppiumFieldDecorator

I made the change in pom.xml as well for execution in pipelines.
I made both changes from the screenshot, and page-factory is working as expected. Glad I don’t have to switch between JDK versions.

Thaks a ton.