java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field

Unable to perform an action on the element.

Getting “java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field”

I’m using the following constructor

public BaseTest() { //Constructor

	PageFactory.initElements(new AppiumFieldDecorator(driver), this);
	System.out.println("print");
	
}

App is successfully launching though.

Configuration:

  1. JDK - v 1.8.0
  2. node - v12.16.2
  3. npm - v6.14.4
  4. appium - v1.17.0

Dependencies:

io.appium
java-client
7.2.0

it should be:

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

where “sec” is some sec time. With your example it will take default = 1 sec. But still should work. We need more code example of your project.

Hi @Aleksei,

Tried it, but getting this exception
The constructor AppiumFieldDecorator(AppiumDriver, int, TimeUnit) is undefined

Here is the code as recommended by you. Still not working.

public class BaseTest {

protected AppiumDriver<MobileElement> driver;
protected Properties props;
InputStream inputStream;

public BaseTest() { //Constructor
	
	PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);
	
	
}

You do not have driver init before. Check good example https://www.google.com/amp/s/blog.testproject.io/2018/07/31/page-object-model-appium-java-android/amp/

Thanks @Aleksei
This worked for me!!

Defined the driver as “static”

public BaseTest() {

PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(10)), this);

}