Screenshot with Selenium WebDriver

0 votes

I’m working on a code using Selenium Webdriver Java and TestNG. How can I take a screenshot using Boolean

public boolean test()throws Exception  {}

Below are the steps I used but it is showing error:

WebDriver driver = new FirefoxDriver();

driver.get("http://www.google.com/");

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Now you can do whatever you need to do with it, for example copy somewhere

FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

The error is showing in this line for the copyFile as

The method copyFile(File, File) is

undefined for the type FileUtils

 FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

Jul 12, 2018 in Selenium by Martin
• 4,220 points
622 views

1 answer to this question.

0 votes

Try the below code:

import java.io.File;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.apache.commons.io.FileUtils;



public  class Test {

public void screenShot() {

    // driver is your WebDriver

    File screenshot = ((TakesScreenshot) driver)

                            .getScreenshotAs(OutputType.FILE);

    FileUtils.copyFile(screenshot, new File(fileName));

}

}
answered Jul 12, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to take screenshot in Selenium WebDriver

In Java, it can be done like ...READ MORE

answered Apr 7, 2018 in Selenium by nsv999
• 5,050 points
397 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
260 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
192 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
629 views
0 votes
1 answer

Firefox browser not opening with given URL using Selenium Webdriver with Java

Download the latest selenium jar and replace ...READ MORE

answered Apr 30, 2018 in Selenium by Samarpit
• 5,130 points
1,906 views
0 votes
1 answer

How to handle notifications in Python with Selenium (Chrome WebDriver)

Below will help you: You can disable the ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,811 views