Getting Nullpointer Exception while taking screen shot

1,655 views
Skip to first unread message

Harish Dhage

unread,
Feb 20, 2015, 10:02:52 AM2/20/15
to seleniu...@googlegroups.com
Hi Guys,

I am getting nullpointer exception for taking screen shot, please check the code

public void grabScreenShot() throws IOException{
System.out.println("in grap screen shot method");  // till here it will work
File screenShotFile = ((TakesScreenshot) drive).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenShotFile, new File("D:\\screenShot.jpeg"));
System.out.println("Screen shot is taken");
}
public void getScreenShot() throws IOException{
System.out.println("x"); // till here it will work
EventFiringWebDriver edrive= new EventFiringWebDriver(drive);
File srcImgFile = edrive.getScreenshotAs(OutputType.FILE);
System.out.println("y");
File dstImgFile = new File("D:/Study/Selenium practices/HybridFramework/src/screenShot/screenShot.jpeg");
FileUtils.copyFile(srcImgFile, dstImgFile);
System.out.println("z");
}

PeterJeffreyGale

unread,
Feb 20, 2015, 10:47:40 AM2/20/15
to seleniu...@googlegroups.com
Which line?

Harish Dhage

unread,
Feb 21, 2015, 3:17:27 AM2/21/15
to seleniu...@googlegroups.com
Hi Peter,

I am getting exception at 

public void grabScreenShot() throws IOException{
System.out.println("in grap screen shot method");  // till here it will work
File screenShotFile = ((TakesScreenshot) drive).getScreenshotAs(OutputType.FILE); // here I am getting NullPointerException
FileUtils.copyFile(screenShotFile, new File("D:\\screenShot.jpeg"));
System.out.println("Screen shot is taken");
}
public void getScreenShot() throws IOException{
System.out.println("x"); // till here it will work
EventFiringWebDriver edrive= new EventFiringWebDriver(drive);  // here I am getting NullPointerException
File srcImgFile = edrive.getScreenshotAs(OutputType.FILE);
System.out.println("y");
File dstImgFile = new File("D:/Study/Selenium practices/HybridFramework/src/screenShot/screenShot.jpeg");
FileUtils.copyFile(srcImgFile, dstImgFile);
System.out.println("z");
}

On Fri, Feb 20, 2015 at 9:17 PM, PeterJeffreyGale <peterjef...@hotmail.co.uk> wrote:
Which line?

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/mask3qsC6o4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9e45decb-e14d-4b65-a371-a8018f02cffc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Harish S Dhage
+91 9986146166

CH!NN@ K

unread,
Feb 21, 2015, 4:07:22 AM2/21/15
to seleniu...@googlegroups.com

---
Thanks & Regards,
Purushotham Karimbedu,
Drupal Developer and QA Engineer,
Website for Selenium : http://techlearn.in


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

PeterJeffreyGale

unread,
Feb 21, 2015, 4:57:54 AM2/21/15
to seleniu...@googlegroups.com
There is no sign of the "drive" object being declared or instantiated in your code.

It is impossible to have two terminal errors in a single program, and the is no indication of how either of your two methods are called. There's obviously more involved than you have shown us.

PeterJeffreyGale

unread,
Feb 21, 2015, 5:01:07 AM2/21/15
to seleniu...@googlegroups.com
Uttam, how does your post answer the question?

murali seleniumtrainer

unread,
Feb 22, 2015, 4:13:10 AM2/22/15
to seleniu...@googlegroups.com
Hi,

As PeterJeffreyGale said, you did not initiated driver object as per code provided.. let see below simple code to take screen shot, off-course you may know it..

WebDriver driver=new FirefoxDriver();
driver.get("http://web page url");
File src=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("E:\\screen.png"));

Thank You
Reply all
Reply to author
Forward
0 new messages