Code trials:
package Pages;
import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.Select;
public class pageBase {
public static WebDriver driver;
public pageBase(WebDriver driver) {
PageFactory.initElements(driver, this);
}
public static void AcceptAlert() {
Alert alert = driver.switchTo().alert();
alert.accept();
}
}
Test page:
public void SignUp(String user_name,String password) throws InterruptedException {
Set_UserName(user_name);
Set_Password(password);
click_SignupBtn();
Thread.sleep(3000);
AcceptAlert();
}
Error:
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.WebDriver.switchTo()" because "Pages.pageBase.driver" is null