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,710 points
27 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 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,400 points
459 views
0 votes
1 answer
0 votes
1 answer

How can we take screenshots of tests in Selenium 2 using C#

We can take screenshots using below function ...READ MORE

answered Mar 23, 2018 in Selenium by nsv999
• 5,030 points
112 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,210 points
247 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,030 points
71 views
0 votes
1 answer
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
441 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
55 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.