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,760 points
678 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,770 points
519 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
603 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
3,462 views
0 votes
1 answer

How can I travel forward and back in a browser using selenium?

You can use the Navigate interface to ...READ MORE

answered Dec 31, 2018 in Selenium by Nabarupa
12,247 views
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,674 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,143 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,221 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
7,874 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
3,200 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
3,238 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