Reputation: 171
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
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
Reputation: 1
Use import org.apache.commons.io.FileUtils
.
This imports the FileUtils
class you need.
Upvotes: 0
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
Reputation: 1
Plz put the exception then it will work fine.
EG: public static void main(String[] args) throws IOException
Upvotes: 0
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
Reputation: 4099
There are two possible explanations.
Upvotes: 3