java-client
java-client copied to clipboard
Help me with an java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field
The problem
I'm trying to run Testng Test. I get an error.
Environment
Appium version (or git revision) that exhibits the issue: 1.7.1 Last Appium version that did not exhibit the issue (if applicable): Desktop OS/version used to run Appium: SierraMac Node.js version (unless using Appium.app|exe): Mobile platform/version under test: 7.0 Real device or emulator/simulator: Real Appium CLI or Appium.app|exe: Appium Link to Appium logs
I get no Logs
Code To Reproduce Issue [ Good To Have ]
public class AndroidTutorial_Page { private AppiumDriver driver;
/*
- This is the title for the Tutorial screen */ // @AndroidFindBy( xpath = "//android.widget.TextView[@text='Enjoy Our Streamlined Design']" ) <--Production build xpath @AndroidFindBy( xpath = "//android.widget.TextView[@text='Renew Eligible Annual Passes']" ) private MobileElement tutorial_Title1;
/*
- This is the Close Button at the top of the tutorial page for the PRODUCTION build */ @AndroidFindBy( id = "com.disney.mdx.wdw.google.debug:id/pulldown_image" ) private MobileElement tutorial_closeButton_Production;
/*
- This is the tutorial close button found on the DEBUG build */ @AndroidFindBy( id = "com.disney.mdx.wdw.google.debug:id/pulldown_image" ) private MobileElement tutorial_close;
/**
- Constructor
- @param driver */ public AndroidTutorial_Page(final AppiumDriver driver) { this.driver = driver; PageFactory.initElements( new AppiumFieldDecorator(driver, AppiumConstants.IMPLICITLY_WAIT_TIMEOUT, TimeUnit.SECONDS), this); }
/**
- verifyTutorialScreen
- @return true if Tutorial screen is displayed */ public boolean verifyTutorialScreen() throws TimeoutException { System.out.println("Waiting for " + tutorial_Title1); AutomationTools.waitForElementToLoad(driver, tutorial_Title1, 10); Assert.assertEquals(true, tutorial_Title1.isDisplayed(), "Tutorial screen not found"); Log.log(driver).info("Verified Tutorial screen"); return true; }
/**
- clickOnDismissScreen
- @return true if closed */ public boolean clickOnDismissScreen() throws TimeoutException { AutomationTools.waitForElementToLoad(driver, tutorial_close, 10); tutorial_close.click(); Log.log(driver).info("Clicked on Dismiss Tutorial"); return true; } ==================================================
Console Logs:
[RemoteTestNG] detected TestNG version 6.13.0 FAILED: test java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field com.disney.appium.pageobjects.Android.Tutorial.AndroidTutorial_Page.tutorial_Title1 to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$dd998978 at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) at java.lang.reflect.Field.set(Field.java:764) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:117) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105) at com.disney.appium.pageobjects.Android.Tutorial.AndroidTutorial_Page.(AndroidTutorial_Page.java:51) at com.disney.appium.scripts.Android.TicketsPasses.AP_Renewal_Verify_that_eligible_expired_AP_Shows_on_Tickets_Passes_with_Renewal_CTA.test(AP_Renewal_Verify_that_eligible_expired_AP_Shows_on_Tickets_Passes_with_Renewal_CTA.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:571) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:707) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:979) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187) at org.testng.TestNG.runSuitesLocally(TestNG.java:1116) at org.testng.TestNG.runSuites(TestNG.java:1028) at org.testng.TestNG.run(TestNG.java:996) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
=============================================== Default test Tests run: 1, Failures: 1, Skips: 0
=============================================== Default suite Total tests run: 1, Failures: 1, Skips: 0
Hi, I am facing the same issue. Can some one please help?
same here, I'm using serenity and pageObject. Worked before I updated dependencies I guess you are using serenity? https://github.com/serenity-bdd/serenity-core/issues/1053
Hi! i have the same issue when i run the test on AWS Device Farm
Hello everybody. I ran into a problem, when i updated my serenity to 1.9.17, i can't use appium Widget(it is a custom element https://github.com/appium/java-client/blob/master/docs/Page-objects.md ), because in new version we don't have PageFactory.initElements(new AppiumFieldDecorator... Please help who solve this problem or give advice. Thanks.
It seems to be the same issue #919 , and I have seen multiple issues on appium side for this, but no progress on any of those, its more likely to be a major bug on appium side, for now the workaround is
@FindBy(id = "com.ebay.mobile:id/title")
WebElement element;
I am facing same issue after extending MobileElement class and used custom class with all page object pattern Appium 1.8.1/java_client 6.0.0/6.1.0 testing 6.14.3
I had a same problem and i solve it. I was using
@BeforeSuite
public void initDriver(){
//...
}
The problem is fixed after adding (alwaysRun = true) after @BeforeSuite
@BeforeSuite(alwaysRun = true)
public void initDriver(){
//...
}
I had a same problem and i solve it. I was using
@BeforeSuite public void initDriver(){ //... }
The problem is fixed after adding (alwaysRun = true) after @BeforeSuite
@BeforeSuite(alwaysRun = true) public void initDriver(){ //... }
Have u able to use the @AndroidFindBy and @iOSFindBy annotations and
PageFactory.initElements(new AppiumFieldDecorator(driver,15,TimeUnit.SECONDS), this);
have you used the above statement ??
i'm getting compiler error for above statement as "undefined" . and
if use PageFactory.initElements(new AppiumFieldDecorator(driver), this);
then its throwing java.lang.IllegalArgumentException
Please reply if any one got the solution
I'm having the same issue, and it surprises me that this thread has been open for a year yet it remains unsolved. I'm using Spring along with Appium and, basically, when I initialize my driver I initialize it like this:
return new AppiumDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
And in my PageObjects I'm declaring my elements like this:
@AndroidFindBy(id = "com.miui.calculator:id/btn_2_s")
private MobileElement buttonTwo;
I really don't think it's an issue on our side, but I may be wrong... Has anyone found something useful that might fix this issue? I really don't want to use WebElement as a workaround.
Can you try this return new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
I actually just managed to fix it. I don't know why but, remember I mentioned I was using Spring? Well, my PageObjects extend from a BasePageObject
and in that class I store the driver as a property. When I initialized my children PageObjects with the PageFactory, I was using my getDriver()
getter method (which I inherit from BasePageObject
) and after I tried adding the driver as a property in each of my children PageObjects and initilizing them by making them equal to the driver from my BasePageObject
the error got fixed. The way I give access my children to the driver is by injecting the instance of the BasePageObject in the constructor using Spring. Something like this:
Before
@Component
public class MyChildrenPageObject extends BasePageObject {
@AndroidFindBy(id = "mySelector")
private MobileElement element
public MyChildrenPageObject() {
PageFactory.initElements(new AppiumFieldDecorator(this.getDriver()), this);
}
}
After
@Component
public class MyChildrenPageObject extends BasePageObject {
private AppiumDriver<MobileElement> driver;
@AndroidFindBy(id = "mySelector")
private MobileElement element
@Autowired
public MyChildrenPageObject(AppiumDriver<MobileElement> driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}
}
So it seems that, even though you might be able to pass the driver as an argument, it needs to be as a property of the PageObjects themselves for elements to be initialized correctly. Not sure though, but that's my conclusion given the actions I took to fix this.
Also, that fixed the error for me but it seems that vladbelo does have the driver as a property of the PageObject so, I'm not sure what could be the cause for elements not being initialzed correctly for him...
I actually just managed to fix it. I don't know why but, remember I mentioned I was using Spring? Well, my PageObjects extend from a
BasePageObject
and in that class I store the driver as a property. When I initialized my children PageObjects with the PageFactory, I was using mygetDriver()
getter method (which I inherit fromBasePageObject
) and after I tried adding the driver as a property in each of my children PageObjects and initilizing them by making them equal to the driver from myBasePageObject
the error got fixed. The way I give access my children to the driver is by injecting the instance of the BasePageObject in the constructor using Spring. Something like this:Before
@Component public class MyChildrenPageObject extends BasePageObject { @AndroidFindBy(id = "mySelector") private MobileElement element public MyChildrenPageObject() { PageFactory.initElements(new AppiumFieldDecorator(this.getDriver()), this); } }
After
@Component public class MyChildrenPageObject extends BasePageObject { private AppiumDriver<MobileElement> driver; @AndroidFindBy(id = "mySelector") private MobileElement element @Autowired public MyChildrenPageObject(AppiumDriver<MobileElement> driver) { this.driver = driver; PageFactory.initElements(new AppiumFieldDecorator(this.driver), this); } }
So it seems that, even though you might be able to pass the driver as an argument, it needs to be as a property of the PageObjects themselves for elements to be initialized correctly. Not sure though, but that's my conclusion given the actions I took to fix this.
Also, that fixed the error for me but it seems that vladbelo does have the driver as a property of the PageObject so, I'm not sure what could be the cause for elements not being initialzed correctly for him...
Solved the issue by Just adding "new AppiumFieldDecorator(this.driver)" to PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
I also got the same issue , My mistake :I used Capital 'W' in wd of appium URL(desired capabilities). Changed that to small 'w' (wd)and its working fine now
Hi I only had this error when I used API 28(Pie) and 29(q) for my android emulator. I created another emulator with API 27(Oreo).
My environment: Appium 1.9.1 Android emulator with API 27.
javac 11.0.5
I actually just managed to fix it. I don't know why but, remember I mentioned I was using Spring? Well, my PageObjects extend from a
BasePageObject
and in that class I store the driver as a property. When I initialized my children PageObjects with the PageFactory, I was using mygetDriver()
getter method (which I inherit fromBasePageObject
) and after I tried adding the driver as a property in each of my children PageObjects and initilizing them by making them equal to the driver from myBasePageObject
the error got fixed. The way I give access my children to the driver is by injecting the instance of the BasePageObject in the constructor using Spring. Something like this: Before@Component public class MyChildrenPageObject extends BasePageObject { @AndroidFindBy(id = "mySelector") private MobileElement element public MyChildrenPageObject() { PageFactory.initElements(new AppiumFieldDecorator(this.getDriver()), this); } }
After
@Component public class MyChildrenPageObject extends BasePageObject { private AppiumDriver<MobileElement> driver; @AndroidFindBy(id = "mySelector") private MobileElement element @Autowired public MyChildrenPageObject(AppiumDriver<MobileElement> driver) { this.driver = driver; PageFactory.initElements(new AppiumFieldDecorator(this.driver), this); } }
So it seems that, even though you might be able to pass the driver as an argument, it needs to be as a property of the PageObjects themselves for elements to be initialized correctly. Not sure though, but that's my conclusion given the actions I took to fix this. Also, that fixed the error for me but it seems that vladbelo does have the driver as a property of the PageObject so, I'm not sure what could be the cause for elements not being initialzed correctly for him...
Solved the issue by Just adding "new AppiumFieldDecorator(this.driver)" to PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
It is still not working for me. I try to run tests on native app with appium v 1.15.0 but ending with same java.lang.IllegalArgumentException. The solution PageFactory.initElements(new AppiumFieldDecorator(this.driver), this); works for my tests running on mobile safari with WebElements only. How do you initialise and pass driver to page classes? I use EnhancedIOSDriver<IOSElement> . I will appreciate any help here
java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field to to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4 when running test in AWS device farm . any one please help .
@hareeshnkp I have the same problem. Locally it works fine but on AWS Device Farm it doesn't work at all. Fails with
java.lang.IllegalArgumentException: Can not set io.appium.java_client.MobileElement field to to org.openqa.selenium.remote.RemoteWebElement$$EnhancerByCGLIB$$d27c0df4
I researched all related issues on the whole Internet and tried a lot of solutions but it doesn't help and seems impossible to solve without AWS Support. Looks like an environment issue (driver version of something else).
It is not an obvious error and it looks like it is the default error. For example: https://stackoverflow.com/q/55630985 Does anyone have any idea how to get a real exception?
Anyone able to resolve this error? I am facing the same issue. seems like there's some issue with @AndroidfindBy its working fine with @findBy annotation. I don't know why.
Ok I got myself sorted, this worked for me: I wasn't passing driver correctly. public firebaseScreen(AndroidDriver driverFromStep) { this.driver=driverFromStep; PageFactory.initElements(new AppiumFieldDecorator(driverFromStep,Duration.ofSeconds(20)),this); } Also refer to this link: https://blog.testproject.io/2018/07/31/page-object-model-appium-java-android/ its really helpful.
Hello, in my case, i find that I have a problem with the initialization of driver and this error initializes driver with null. The problem is that the PageFactory.initElemnts don't show the real error. I suggest check if the driver is not null before call the PageFactory.initElemnts
For people getting this exception on AWS while everything works OK locally... What helped me was to try different combinations of client and server versions, e.g. these setups work fine when project executed against AWS:
- server: v1.18.3 (Oct 27, 2020), client: v7.2.0 (Aug 27, 2019)
- server: v1.15.1 (Oct 13, 2019), client: v7.2.0 (Aug 27, 2019)
Above solution requires using custom environment on AWS Device Farm to select appropriate Appium server version. Client version is set in your testing project (e.g. pom.xml), before building zip-with-dependencies.zip
Hello! I think I have a solution. i've found that the driver = null when i've executed class (which contain PageFactory.initElemnts). So i've executed class after when the driver has not already been = 0