Sunday 15 March 2015

java.lang.NullPointerException when running a testcase via Selenium webDriver in Chrome -


is my class that uses selenium Vebdraivr and throws the error

  public Class Test_Chromedriver {public static WebDriver driver; Public static void main (String [] Algs) {try {System.setProperty ( "webdriver.chrome.driver", "E: \\ jars \\ chromedriver.exe"); WebDrive Drivers = New Chrome Drivers (); Driver.get ("http://www.facebook.com"); Driver.findElement (By.id ("email")) SendKeys ("Sun") .; Driver.findElement (By.name ("passed")) SendKeys ("Hello"). } Hold (exception e) {e.printStackTrace (); } Finally {driver.close (); Driver.quit (); }   

Once I received went down to the code above, the error message:

  start ChromeDriver port = 12877 version = 23.0.1240.0 log = D: \ Eclipse Juno workspace \ aS selenium workspace \ web Drivr application \ Kromriarovrklog exception thread "main" java.lang.NullPointerException Test_Chromedriver.main (Test_Chromedriver.java:25)  < / Pre> 

Note: WebDowners add values ​​to the field after Chrome browser opens, but the above correction of the console Is displayed every time and does not perform last.

Your trouble comes from your try / catch and especially your Finally .

Because your driver is only localy in your try {} ... so your eventually is something with your driver I can not change the name of your drivers and help you see what happens here.

  public class Test_Chromedriver {public static WebDriver driver NULL; // & lt; - ever public static void main (do not instantiate the string [] ARG) {try {System.setProperty ( "webdriver.chrome.driver", "E: \\ jars \\ chromedriver.exe"); WebDriver driver OK = new ChromeDowner (); // & lt; - OK.get local variable driver ("http://www.facebook.com"); DriverOK.findElement (By.id ("Email")) SendKeys ("Sun") .; DriverOK.findElement (By.name ("passed")) SendKeys ("Hello"). } Hold (exception e) {e.printStackTrace (); } Finally {driverNULL.close (); // & lt; - If you want to close an object, tap pointer exception driver NULL.quit (); }}}   

What can you do now?

  public class Test_Chromedriver {public static WebDriver driver; Public static void main (String [] Algs) {try {System.setProperty ( "webdriver.chrome.driver", "E: \\ jars \\ chromedriver.exe"); Driver = new chrome driver (); // & lt; - Remove Webdriver type driver.get ("http://www.facebook.com"); Driver.findElement (By.id ("email")) SendKeys ("Sun") .; Driver.findElement (By.name ("passed")) SendKeys ("Hello"). } Hold (exception e) {e.printStackTrace (); } Finally {driver.close (); Driver.quit (); }}}    

No comments:

Post a Comment