Ram
Ram

Reputation: 171

Saving Screenshot file

My code for saving screenshot file is:

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshots\\"+Filename+".jpg"));

The Error is :

The method copyFile (File, File)is undefined for the type FileUtil

I use an EventFiringWebDriver . Any ideas on this.

Upvotes: 4

Views: 12854

Answers (6)

Yusuf
Yusuf

Reputation: 33

I had this error too what caused the error for me was that I added the wrong package

the package I needed to add was selenium:

import org.openqa.selenium.io.FileHandler;

but this is the wrong package I added:

import java.util.logging.FileHandler;

so be careful when choosing a package.

Upvotes: 0

balaji
balaji

Reputation: 1

Use import org.apache.commons.io.FileUtils. This imports the FileUtils class you need.

Upvotes: 0

tulasi
tulasi

Reputation: 1

public class Testscreenshot {

public static void main(String[] args) throws IOException {
    System.out.println("Images saved ..");
         WebDriver driver = new FirefoxDriver();
        driver.get("https://google");
        File scrFile;
        scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

     org.apache.commons.io.FileUtils.copyFile(scrFile, new File("C:\\Users\\R&D\\Desktop\\Tulas\\Javafiles\\testimages.png"));

        driver.quit();
       }
    }

Upvotes: 0

Mayuran
Mayuran

Reputation: 1

Plz put the exception then it will work fine.

EG: public static void main(String[] args) throws IOException

Upvotes: 0

some_other_guy
some_other_guy

Reputation: 3414

import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

I guess you missed one or more of these imports.. The code given above works fine for me with these includes.

Upvotes: 0

JacekM
JacekM

Reputation: 4099

There are two possible explanations.

  1. The error message you provided mentions FileUtil class instead of FileUtils You may have used wrong class by mistake.
  2. Assuming you are using the correct FileUtils class you may have imported wrong package. Make sure that you have imported org.apache.commons.io.FileUtils

Upvotes: 3

Related Questions