I am implementing pagefactory in my Page object model automation framework. My existing framework works fine without pagefactory. Now I am implementing pagefactory to invoke elements. I am facing a issue where Pagefactory element throwing null values. I have a doubt that it may be because of constructors not sure.
I have build a framework based on Page Object Model Have packages as below :- com.automationframework com.configutaion com.pageObject com.testcases com.testsuites
My testsuites classes invokes testcases present in testcases package and invoke driver and other framework based classes in automationframework. I know it's hard to grab the error by simply read few stuff but may anyone faced same issue and can help me.
My Page class looks something like below :-
public class SynchronizationPage extends Page {
ExcelLib xl = new ExcelLib();
private WebElement element = null;
public SynchronizationPage(WebDriver driver) {
super(driver);
}
protected boolean isSecured() {
return true;
}
@FindBy(how = How.XPATH, using = "//a[@class='header-font']/span[@class='icon-cog']")
@CacheLookup
public WebElement HoverOnSettings;
}
My testcase class :-
public class SyncTest extends AutomationTestCaseVerification {
// SynchronizationPage sync = new SynchronizationPage(Page.driver);
SignOutPage signout = new SignOutPage(Page.driver);
ExcelLib xl = new ExcelLib();
SynchronizationPage synccc = PageFactory.initElements(Page.driver, SynchronizationPage.class);
private WebElement element = null;
private WebDriver driver;
public SyncTest() {
super();
}
@Override
protected void verifyTestCases() throws Exception {
syncFeature();
}
public void syncFeature() throws Exception {
try {
WebDriverWait waits = new WebDriverWait(Page.driver, 60);
// waits.until(ExpectedConditions.elementToBeClickable(synccc.clickOnOffButton)).click();
synccc.clickOnOffButton.click();
System.out.println("Yes I clicked");
}
catch(Exception ex)
{
System.out.println("error ="+ex.getMessage());
}
}
}
I am getting error like below :-
java.lang.NullPointerException at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69) at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38) at com.sun.proxy.$Proxy5.click(Unknown Source) at com.cc.automation.testcases.SyncTest.syncFeature(SyncTest.java:130) at com.cc.automation.testcases.SyncTest.verifyTestCases(SyncTest.java:60) at com.cc.automation.automationframework.AutomationTestCaseVerification.Execute(AutomationTestCaseVerification.java:58) at com.cc.automation.testsuites.SynchronizationTest.testSync(SynchronizationTest.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) at org.testng.internal.Invoker.invokeMethod(Invoker.java:661) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:744) at org.testng.TestRunner.run(TestRunner.java:602) at org.testng.SuiteRunner.runTest(SuiteRunner.java:380) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) at org.testng.SuiteRunner.run(SuiteRunner.java:289) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301) at org.testng.TestNG.runSuitesLocally(TestNG.java:1226) at org.testng.TestNG.runSuites(TestNG.java:1144) at org.testng.TestNG.run(TestNG.java:1115) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
I have also tried to apply below but still not working :-
PageFactory.initElements(this.driver, this);




com.cc.automation.testcases.SyncTest.syncFeature(SyncTest.java:130). Which line exactly is that?synccc.clickOnOffButton.click();Stop test in debug on that place and check ifsyncccobject is not null , same withclickOnOffButton. Where it initialized? ProbablyclickOnOffButtonis null.