Selenium Webdriver Implementation screenshot function

Source: Internet
Author: User

Refer to Http://www.cnblogs.com/tobecrazy/p/3599568.html

Webdriver, you need to introduce:

ImportJava.io.File;ImportJava.io.IOException;ImportOrg.apache.commons.io.FileUtils;ImportOrg.openqa.selenium.OutputType;Import Org.openqa.selenium.TakesScreenshot;

Method
public static void Snapshot (Takesscreenshot drivername, String filename)
{
This method would take the screen shot, require-parameters, one is driver name, and another is file name

String Currentpath = System.getproperty ("User.dir"); Get Current Work folder
System.out.println (Currentpath);
File scrfile = Drivername.getscreenshotas (outputtype.file);
Now you can do whatever need to do with it, for example copy somewhere
try {
System.out.println ("Save snapshot Path is:" +currentpath+ "/" +filename);
Fileutils.copyfile (Scrfile, New File (currentpath+ "\ \" +filename));
} catch (IOException e) {
TODO auto-generated Catch block
System.out.println ("Can ' t Save screenshot");
E.printstacktrace ();
}
Finally
{

System.out.println ("screen shot finished");
}
}


Search for selenium on Baidu and then

Selenium Webdriver Implementation function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.