Selenium java.lang.NullPointerException with PageFactory -
i'm trying hang of pagefactory pom, not working , can not understand wrong.
this first pom class home page:
package pagefactory; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.support.findby; import org.openqa.selenium.support.pagefactory; public class home_page_pof { public webdriver driver; @findby(css = "div#header-profile a#header-profile-toggle") public webelement profiletogglebutton; @findby(css = "form#loginuserdataform div.footer div.add-footer a.btn.btn-link.linkicon") public webelement newregistrationbutton; public home_page_pof(webdriver driver) { this.driver = driver; pagefactory.initelements(driver, this); } }
this second pom class reg. page
package pagefactory; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.support.findby; import org.openqa.selenium.support.pagefactory; import org.openqa.selenium.support.ui.select; public class registration_page_pof { public webdriver driver; //personal details webelements @findby(css = "form#personaldetailsform div.profile.pe div.profile-block.simple.first fieldset#pefield-title select#pesalutation") public webelement titledropdown; public select titleselect = new select(titledropdown); public registration_page_pof(webdriver driver) { this.driver = driver; pagefactory.initelements(driver, this); } }
and test case:
package tests; import pagefactory.home_page_pof; import pagefactory.registration_page_pof; import org.openqa.selenium.webdriver; import org.openqa.selenium.chrome.chromedriver; import org.openqa.selenium.io.temporaryfilesystem; import org.openqa.selenium.support.ui.select; import org.testng.annotations.afterclass; import org.testng.annotations.beforeclass; import org.testng.annotations.test; import java.util.concurrent.timeunit; public class test_pof { public webdriver driver; home_page_pof objhomepage; registration_page_pof objregpage; @beforeclass public void browsersetup() { system.setproperty("webdriver.chrome.driver", "d:/install/selenium-2.53.0/drivers/chromedriver.exe"); driver = new chromedriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlywait(5, timeunit.seconds); driver.navigate().to("http://www.lufthansa.com/"); } @afterclass public void brosercleanup() { if (driver != null) { temporaryfilesystem.getdefaulttmpfs().deletetemporaryfiles(); driver.close(); driver.quit(); } } @test public void test0001() { objhomepage = new home_page_pof(driver); objhomepage.profiletogglebutton.click(); objhomepage.newregistrationbutton.click(); objregpage = new registration_page_pof(driver); select titleselect = new select(objregpage.titledropdown); titleselect.selectbyvisibletext("mr."); } }
so homepage objects working fine, click on 2 buttons , proceed registration page. after want select value dropdown, gives me nullpointerexception:
java.lang.nullpointerexception @ org.openqa.selenium.support.ui.select.<init>(select.java:44) @ pagefactory.registration_page_pof.<init>(registration_page_pof.java:17) @ tests.test_pof.test0001(test_pof.java:56) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ org.testng.internal.methodinvocationhelper.invokemethod(methodinvocationhelper.java:85) @ org.testng.internal.invoker.invokemethod(invoker.java:639) @ org.testng.internal.invoker.invoketestmethod(invoker.java:816) @ org.testng.internal.invoker.invoketestmethods(invoker.java:1124) @ org.testng.internal.testmethodworker.invoketestmethods(testmethodworker.java:125) @ org.testng.internal.testmethodworker.run(testmethodworker.java:108) @ org.testng.testrunner.privaterun(testrunner.java:774) @ org.testng.testrunner.run(testrunner.java:624) @ org.testng.suiterunner.runtest(suiterunner.java:359) @ org.testng.suiterunner.runsequentially(suiterunner.java:354) @ org.testng.suiterunner.privaterun(suiterunner.java:312) @ org.testng.suiterunner.run(suiterunner.java:261) @ org.testng.suiterunnerworker.runsuite(suiterunnerworker.java:52) @ org.testng.suiterunnerworker.run(suiterunnerworker.java:86) @ org.testng.testng.runsuitessequentially(testng.java:1215) @ org.testng.testng.runsuiteslocally(testng.java:1140) @ org.testng.testng.run(testng.java:1048) @ org.testng.idearemotetestng.run(idearemotetestng.java:74) @ org.testng.remotetestngstarter.main(remotetestngstarter.java:121) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ com.intellij.rt.execution.application.appmain.main(appmain.java:144)
the problem initializing varaible titleselect
in class itself. initialize inside constructor or after finding element;
public class registration_page_pof { public webdriver driver; //personal details webelements @findby(css = "form#personaldetailsform div.profile.pe div.profile-block.simple.first fieldset#pefield-title select#pesalutation") public webelement titledropdown; public select titleselect; //dont initialize here public registration_page_pof(webdriver driver) { this.driver = driver; pagefactory.initelements(driver, this); titleselect = new select(titledropdown);//initialize here } }
Comments
Post a Comment