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,720 points
66 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 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,420 points
664 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can I clear the text in a text box using Selenium WebDriver?

Hello Akriti, you can clear the text ...READ MORE

answered May 29 in Selenium by Anvi
• 12,840 points
191 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,090 points
551 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
888 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
550 views
0 votes
1 answer
0 votes
1 answer