I'm using Java,Selenium web driver and TestNG framework. I have a method to click a button in web page. But it didn't work. When debugging I could find xpath is not passed to the button. Then I tried giving xpath in the same place where click event is called using driver.findElement(By.xpath.....). It worked without any error. I have included my codes below. Please check and help me to solve 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
@FindBy(xpath = "your xpath") private WebElement btnSubmit;