0

I have one screen where I click on the About us button, after that click on more button(shows full details of about us section). After that taking a screenshot of the screen but the screen goes to the top of the page and the screenshot is taken. I want a screenshot of the page which is displayed after clicking About us-> more button.

  • Does this answer your question? [How to take screenshot with Selenium WebDriver](https://stackoverflow.com/questions/3422262/how-to-take-screenshot-with-selenium-webdriver) – Brydenr Dec 31 '19 at 17:07

1 Answers1

0

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(url);
    Thread.sleep(2000);
    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
  ImageIO.write(screenshot.getImage(),"PNG",new                              
File(System.getProperty("user.dir") +"/Screenshots/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.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
13b
  • 31
  • 1
  • same code I have written but it is taking a screenshot of the top page. –  Jan 02 '20 at 05:06
  • Hi @VarshaKadam please visite below link,it will help you https://dzone.com/articles/using-selenium-webdriver-for-full-page-screenshots – 13b Jan 02 '20 at 07:04