Null point exception while running WebDriver script

06 January, 2014
This is a simple mistake which may take time to debug. While running a script I got the errors as below:

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)


The script which had the syntax error:


import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  
import org.openqa.selenium.firefox.FirefoxProfile;  
import org.testng.annotations.BeforeTest;  
import org.testng.annotations.Test;  
  
public class SignIn {  
   
 WebDriver driver;  
   
 @BeforeTest  
 public void start(){  
 WebDriver driver = new FirefoxDriver();  
 }  
   
 @Test  
 public void SignIn()  
 {  
 driver.get("http://facebook.com/");  
 driver.manage().window().maximize();  
 }  
  
}  
The above script was throwing the exception because the of the redeclaration of "WebDriver" inside the @BeforeTest method. Remove the "WebDriver" statement and the script runs successfully.

The modified script which runs successfully:


import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  
import org.openqa.selenium.firefox.FirefoxProfile;  
import org.testng.annotations.BeforeTest;  
import org.testng.annotations.Test;  
  
public class AutoComplete {  
   
 WebDriver driver;  
   
 @BeforeTest  
 public void start(){  
 driver = new FirefoxDriver();  
 }  
   
 @Test  
 public void AutoComplete()  
 {  
 driver.get("http://mythoughts.co.in/");  
 driver.manage().window().maximize();  
 }  

No comments:

Post a Comment