How can I take a screenshot using selenium

0 votes
I want a screenshot of my browser for the current page i have searched for. How can I do that using selenium?

I am using eclipse and am writing the codes in Java.

Any help will be appreciated. Thank you
Dec 31, 2018 in Selenium by Sradha
• 1,750 points
277 views

1 answer to this question.

0 votes

Hello @Sradha, You can use the File screenshotFile = (((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE)); to create a screenshot of the browser.

Here is the code that I am using hope you find it useful.

       System.setProperty("webdriver.chrome.driver","C:\\Users\\priyj_kumar\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.amazon.com");
driver.findElement(By.id("twotabsearchtextbox")).sendKeys("Headphone",Keys.ENTER);
File screenshotFile = (((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE));
FileUtils.copyFile(screenshotFile, new File("C:\\Users\\priyj_kumar\\Downloads\\screenshot.png"));

Hope this helps.

answered Dec 31, 2018 by Nabarupa

Related Questions In Selenium

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,970 points
84 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,970 points
130 views
0 votes
1 answer

How to take screenshot of a frame using Selenium WebDriver?

you can use the below code: import java.awt.image.BufferedImage; import ...READ MORE

answered Jun 20, 2018 in Selenium by Meci Matt
• 9,460 points
2,155 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
6,215 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
6,573 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,890 points
4,198 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
5,203 views
0 votes
1 answer

How can I scroll a web page in Mozilla Firefox using Selenium?

Hi Rohan, steps to scroll a webpage in ...READ MORE

answered May 14, 2019 in Selenium by Pratibha
• 3,690 points
1,574 views
0 votes
1 answer

How can I refresh a browser window in different ways using Selenium Webdriver?

Hello Piyush, you can refresh a browser ...READ MORE

answered May 29, 2019 in Selenium by Anvi
• 14,150 points
1,929 views