i tried to write a Click() function in Serenity-bdd as Common methods to use in the framework. But, the webpage element which i stored it as WebElementFacade to call inside the Click() function as below. it is not identifying the element and clicking. it is throwing error as **"NullpointerException"**
.Please help where i went wrong.
Note : if i use the Webelement as Target type it is working fine. But i need element as the WebElementFacade function to check for more conditions. please help to solve
WebElementFacade --> Stored in different (.java) like below,
public class ParabankForm extends PageObject {
public WebElementFacade REGISTER_BUTTON = $(By.xpath("//*[text()='Register']"));
}
Function:
/*
* Function Name : Click()
* Author: Koushick Sudharsanam
* Purpose: The Actor is used to click on the Webelement Target in Webpage
*
*/
public void Click(Actor act, WebElementFacade target) {
if(target.isDisplayed()||target.isClickable())
{
act.attemptsTo(Click.on(target));
}
else
{
act.wasAbleTo(target.waitUntilClickable());
if(target.isCurrentlyEnabled() && target.isClickable())
{
act.attemptsTo(Click.on(target));
}
}
}
So in Step-definition i will call like this,
@Then("i click on the RegisterButton")
public void i_click_on_the_register_button() {
Utiltiesfunction.GetInstance().Click(act, obj.REGISTER_BUTTON);
}
Error:
java.lang.NullPointerException
at net.serenitybdd.core.pages.WebElementResolverByLocator.resolveForDriver(WebElementResolverByLocator.java:25)
at net.serenitybdd.core.pages.WebElementFacadeImpl.getResolvedELement(WebElementFacadeImpl.java:234)
at net.serenitybdd.core.pages.WebElementFacadeImpl.getElement(WebElementFacadeImpl.java:229)
at net.serenitybdd.core.pages.WebElementFacadeImpl.isDisplayed(WebElementFacadeImpl.java:1351)
at CucumberRunner.my.commonfunction.Utiltiesfunction.Click(Utiltiesfunction.java:37)
at CucumberRunner.my.stepdefinitions.Parabankdef.i_click_on_the_register_button(Parabankdef.java:84)