Appium - PageFactory initElements is not working





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have this Class as my page object:



public class LaunchPageObject  {

private AppiumDriver<AndroidElement> driver;

public LaunchPageObject() {

}

public LaunchPageObject(AppiumDriver<AndroidElement> driver) {

this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}

public void Click_SigninNow() {

lnk_SigninNow.click();
}

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}


and I have this class as my test case class:



public class LaunchPageTest extends Android {

@Test
public void Click_SigninNow() throws MalformedURLException {

LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}


I have this error log:




FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




The test opens the app but is not able to click the element. Any idea what is happening here?










share|improve this question

























  • Can you add setDriver() method too?

    – Suban Dhyako
    Nov 23 '18 at 9:01











  • I think setting your AppiumDriver as static will solve the problem.

    – Suban Dhyako
    Nov 23 '18 at 11:40


















1















I have this Class as my page object:



public class LaunchPageObject  {

private AppiumDriver<AndroidElement> driver;

public LaunchPageObject() {

}

public LaunchPageObject(AppiumDriver<AndroidElement> driver) {

this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}

public void Click_SigninNow() {

lnk_SigninNow.click();
}

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}


and I have this class as my test case class:



public class LaunchPageTest extends Android {

@Test
public void Click_SigninNow() throws MalformedURLException {

LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}


I have this error log:




FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




The test opens the app but is not able to click the element. Any idea what is happening here?










share|improve this question

























  • Can you add setDriver() method too?

    – Suban Dhyako
    Nov 23 '18 at 9:01











  • I think setting your AppiumDriver as static will solve the problem.

    – Suban Dhyako
    Nov 23 '18 at 11:40














1












1








1








I have this Class as my page object:



public class LaunchPageObject  {

private AppiumDriver<AndroidElement> driver;

public LaunchPageObject() {

}

public LaunchPageObject(AppiumDriver<AndroidElement> driver) {

this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}

public void Click_SigninNow() {

lnk_SigninNow.click();
}

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}


and I have this class as my test case class:



public class LaunchPageTest extends Android {

@Test
public void Click_SigninNow() throws MalformedURLException {

LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}


I have this error log:




FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




The test opens the app but is not able to click the element. Any idea what is happening here?










share|improve this question
















I have this Class as my page object:



public class LaunchPageObject  {

private AppiumDriver<AndroidElement> driver;

public LaunchPageObject() {

}

public LaunchPageObject(AppiumDriver<AndroidElement> driver) {

this.driver=driver;
PageFactory.initElements(new AppiumFieldDecorator(this.driver), this);
}

public void Click_SigninNow() {

lnk_SigninNow.click();
}

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}


and I have this class as my test case class:



public class LaunchPageTest extends Android {

@Test
public void Click_SigninNow() throws MalformedURLException {

LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}


I have this error log:




FAILED: Click_SigninNow
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at POM.LaunchPageObject.(LaunchPageObject.java:35)
at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




The test opens the app but is not able to click the element. Any idea what is happening here?







appium appium-android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 4:29









Wasiq Bhamla

709159




709159










asked Nov 22 '18 at 23:06









HamidHamid

13310




13310













  • Can you add setDriver() method too?

    – Suban Dhyako
    Nov 23 '18 at 9:01











  • I think setting your AppiumDriver as static will solve the problem.

    – Suban Dhyako
    Nov 23 '18 at 11:40



















  • Can you add setDriver() method too?

    – Suban Dhyako
    Nov 23 '18 at 9:01











  • I think setting your AppiumDriver as static will solve the problem.

    – Suban Dhyako
    Nov 23 '18 at 11:40

















Can you add setDriver() method too?

– Suban Dhyako
Nov 23 '18 at 9:01





Can you add setDriver() method too?

– Suban Dhyako
Nov 23 '18 at 9:01













I think setting your AppiumDriver as static will solve the problem.

– Suban Dhyako
Nov 23 '18 at 11:40





I think setting your AppiumDriver as static will solve the problem.

– Suban Dhyako
Nov 23 '18 at 11:40












1 Answer
1






active

oldest

votes


















2














Keep your page object and test classes like below



public class LaunchPageObject {

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;

public void click_SigninNow() {
lnk_SigninNow.click();
}

}




public class LaunchPageTest extends Android {

LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);

@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}

}





share|improve this answer
























  • Thank you! it worked :)

    – Hamid
    Nov 23 '18 at 14:38











  • Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

    – Bill Hileman
    Dec 4 '18 at 16:34











  • Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

    – Balakrishnan A
    Dec 25 '18 at 5:00












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438918%2fappium-pagefactory-initelements-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Keep your page object and test classes like below



public class LaunchPageObject {

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;

public void click_SigninNow() {
lnk_SigninNow.click();
}

}




public class LaunchPageTest extends Android {

LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);

@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}

}





share|improve this answer
























  • Thank you! it worked :)

    – Hamid
    Nov 23 '18 at 14:38











  • Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

    – Bill Hileman
    Dec 4 '18 at 16:34











  • Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

    – Balakrishnan A
    Dec 25 '18 at 5:00
















2














Keep your page object and test classes like below



public class LaunchPageObject {

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;

public void click_SigninNow() {
lnk_SigninNow.click();
}

}




public class LaunchPageTest extends Android {

LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);

@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}

}





share|improve this answer
























  • Thank you! it worked :)

    – Hamid
    Nov 23 '18 at 14:38











  • Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

    – Bill Hileman
    Dec 4 '18 at 16:34











  • Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

    – Balakrishnan A
    Dec 25 '18 at 5:00














2












2








2







Keep your page object and test classes like below



public class LaunchPageObject {

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;

public void click_SigninNow() {
lnk_SigninNow.click();
}

}




public class LaunchPageTest extends Android {

LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);

@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}

}





share|improve this answer













Keep your page object and test classes like below



public class LaunchPageObject {

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;

public void click_SigninNow() {
lnk_SigninNow.click();
}

}




public class LaunchPageTest extends Android {

LaunchPageObject lp = PageFactory.initElements(getDriver(), LaunchPageObject.class);

@Test
public void Click_SigninNow() throws MalformedURLException {
lp.Click_SigninNow();
}

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 10:06









Balakrishnan ABalakrishnan A

1415




1415













  • Thank you! it worked :)

    – Hamid
    Nov 23 '18 at 14:38











  • Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

    – Bill Hileman
    Dec 4 '18 at 16:34











  • Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

    – Balakrishnan A
    Dec 25 '18 at 5:00



















  • Thank you! it worked :)

    – Hamid
    Nov 23 '18 at 14:38











  • Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

    – Bill Hileman
    Dec 4 '18 at 16:34











  • Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

    – Balakrishnan A
    Dec 25 '18 at 5:00

















Thank you! it worked :)

– Hamid
Nov 23 '18 at 14:38





Thank you! it worked :)

– Hamid
Nov 23 '18 at 14:38













Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

– Bill Hileman
Dec 4 '18 at 16:34





Can you explain why this worked for this poster? The only real difference I can see is that you are not doing a more standard (in my opinion) passing of the driver object as a parameter to the page object and initializing the page object elements inside the page object itself. Or is there something else I'm missing?

– Bill Hileman
Dec 4 '18 at 16:34













Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

– Balakrishnan A
Dec 25 '18 at 5:00





Thanks Bill for your comments.. I used to follow the different kind of options. Whenever i used to create the page object and will create the respective action method. (Example : if you create object for button and will create the respective action click in the same class ) When coming to the driver creation will create all kind of driver as static method and used to keep the driver into ThreadLoacl .. It will be more helpful for parallel execution..

– Balakrishnan A
Dec 25 '18 at 5:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438918%2fappium-pagefactory-initelements-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?