Unable to take the screenshot of the entire page in chrome using webdriver

0 votes

How to take the screenshot of the full page and how to scroll the page with this code:

JavascriptExecutor js = ((JavascriptExecutor) driver);
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");

This directly moves to the end of the page.

Mar 26, 2018 in Selenium by nitinrawat895
• 11,380 points
3,650 views

1 answer to this question.

+1 vote

I solved this issue myself actually. I downloaded the ashot.jar file first and added it to the project along with other Selenium JAR files

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
import javax.imageio.ImageIO;
import java.io.File;

public class PageScreenShot
{
   public static void main(String args[]) throws Exception
   {
 System.setProperty("webdriver.gecko.driver","D:\\Selenium\\geckodriver.exe");
      WebDriver driver = new ChromeDriver();
    driver.get("https://www.edureka.co/");
    Thread.sleep(2000);
    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
  ImageIO.write(screenshot.getImage(),"PNG",new                              
File(System.getProperty("user.dir") +"/ErrorScreenshots/FullPageScreenshot.png"));
   }
}

It will scroll the page down to the very end and capture the screenshot. And we can control the scroll speed using the viewportPasting method. :)

answered Mar 26, 2018 by nitinrawat895
• 11,380 points
Hi Nitin, thanks for the answer, that actually worked for me. I am Upvoting your answer as it is a very clear and explained.

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,910 views
+1 vote
2 answers
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
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 14, 2020 in Selenium by Gitika
• 65,770 points
103,024 views
0 votes
0 answers

Unable to pass url in firefox and chrome by using selenium webdriver

Hi All, I am not able to run ...READ MORE

May 1, 2019 in Selenium by anonymous

edited May 2, 2019 by Omkar 1,611 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,673 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,142 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
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