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 13, 2018 in Selenium by Martin
• 4,320 points
4,746 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 13, 2018 by Samarpit
• 5,910 points
copyFile method not getting in selenium
Check if you have import FileUtils, it's an apache commons library, you need to download the jar if not yet in your workspace.

Related Questions In Selenium

+1 vote
2 answers
0 votes
1 answer

How can I take a screenshot with Selenium WebDriver?

Yes, it is possible. The following example ...READ MORE

answered Nov 27, 2020 in Selenium by Gitika
• 65,770 points
516 views
0 votes
1 answer

How can I take a screenshot with Selenium WebDriver?

Java Yes, it is possible. The following example ...READ MORE

answered Dec 4, 2020 in Selenium by Gitika
• 65,770 points
599 views
0 votes
1 answer
0 votes
2 answers

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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
0 votes
2 answers

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

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,883 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,910 points
7,209 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,910 points
7,774 views
+1 vote
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,910 points
14,416 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP