I’m using Java,Selenium web driver and TestNG framework. I have a method to a in web page. But it didn’t work. When debugging I could find xpath is not passed to the . Then I tried giving xpath in the same place where is called using driver.findElement(By.xpath…..). It worked without any . I have included my codes below. Please check and help me to this problem.

ClickNewButton();      

// Method body   
public void ClickNewButton() {click(NewButton);}       

@FindBy(xpath = Locators.newButton)  // In this place newButton has it's xpath
WebElement NewButton;  // Here NewButtton doesn't contain any xpath. It's null (This is where problem occurs exactly)

// Xpath in Locators class
public static final String newButton = "html/body/div[2]/div[2]/div/div[2]/div/div[1]/div[3]/div[2]/div[1]/div/div[2]/div/div[3]/div/div[2]/button";               



// click method's body in Base class
public void click(WebElement webElement) {
    webElement.click();
}

Please note that first three code segments are in same class and that class is extended from Base class



Source link https://sqa.stackexchange.com/questions/33478/how-to-solve-java-lang-nullpointerexception-error-in-button-click-event

LEAVE A REPLY

Please enter your comment!
Please enter your name here