-1

I am getting exception

   Exception in thread "main" java.lang.NullPointerException
   at com.wd.programs.Gmail_Login.email(Gmail_Login.java:17)
   at com.wd.programs.Gmail_Login.main(Gmail_Login.java:29)

while running the following code.

 public class Gmail_Login extends HandlingDropdowns  {
    WebDriver driver ;

    public Gmail_Login (WebDriver d) {
      super(d);
    }

    public void email(String e) {

      driver.findElement(By.cssSelector("input[type='email']")).sendKeys(e);
    } 


    public static void main(String[] args) {
      WebDriver driver = new FirefoxDriver();
      Gmail_Login gl = new Gmail_Login(driver);
      gl.openApplication("http://www.gmail.com");
      gl.email("rize.test1");

    }

 }
PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
  • 'driver' is never initialized. So **driver.findElement...** will give null pointer exception. Inside constructor, use **driver = d**. – Sugan Apr 20 '17 at 16:25

1 Answers1

0

You are not assigning the WebDriver instance passed to Gmail_Login class's WebDriver instance. Hence the driver variable in Gmail_Login class has a value null. When you attempt to call any method using this variable with value null, it will throw a NullPointerException. Do this and it will fix the exception:

public Gmail_Login (WebDriver d) {
    super(d);
    this.driver = d;
}
Jayesh Doolani
  • 1,233
  • 10
  • 13