0

I have list of https URLs, now my requirement is to take the screen shot of web pages associated with URLs using java code.

And just for the modularity , I have partitioned my requirement in to three cases:

  1. Automated login in to all the mentioned URLs.

When I run the java code it should take the individual URL and pass the user name and password to the URL.If the user name and password are correct then the webpage associate d with the URL should be displayed. Note: The request from browser to webserver will be redirected through the siteminder so called SSO configuration

  1. Take the screen shot of opened URL.

Now I have webpage opened ,Take the screen shot of the webpage.

  1. Save the screen shots and send it over email.

All the captured screenshots should be copied into a document say PDF and send the document over e mail

Now among the three above mentioned requirements the second has been done partially as iam able to take the screen shot of all the URLs.

Note : Heared of selenium web driver etc but I don't like to go with anything other than normal java stuff.

Thanks in Advance

nagSays
  • 1
  • 4
  • See this post: http://stackoverflow.com/questions/1504034/take-a-screenshot-of-a-web-page-in-java – Zack Jul 26 '16 at 18:26

2 Answers2

2

You can use selenium Take a screenshot with Selenium WebDriver:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

You'll need more code around this to login to each site, mail them, etc ...

For example, to login you'll use something like this:

         WebElement element = driver.findElement(By.id("Email"));
         element.sendKeys("xyz@gmail.com");

         //Enter Password
         WebElement element1 = driver.findElement(By.id("Passwd"));
         element1.sendKeys("Password");

         //Submit button
         element.submit();

You can search for how to use JavaMail to send attachments.

Community
  • 1
  • 1
Dave
  • 13,518
  • 7
  • 42
  • 51
0

You can use Google PageSpeed Insights API to capture the real time screenshot of the website. You can simply make a call to the Google PageSpeed Insights url,Here is an example which will give you JSON result with different options of url=http://www.google.com

https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=http://www.google.com&screenshot=true
sridharnetha
  • 2,104
  • 8
  • 35
  • 69