-2
  • I need to take screenshots of multiple separate shopping websites for the final checkout page.
  • All selections of items in cart and other navigation to pages must be through code.
  • The output screenshots should be in image file(jpg,png) or inserted in a docx file(if possible)
  • What tool and technology can I use for this task?

I have a little idea about screen capture through php and phantomjs but for a static webpage only. I am a newbie and would be happy if someone guides me here.

For example:

To open google.com, search for "stackoverflow" and further opening stackoverflow.com and take a screenshot of the homepage. These steps must be done via code (i.e) automated. Thanks in advance guyz!!

  • Please check this link http://superuser.com/questions/55999/how-can-i-automatically-take-a-screenshot-of-a-website-at-a-specified-time – madankundu Sep 29 '16 at 11:38
  • PhantomJS has also features for automation (http://phantomjs.org/page-automation.html) and since you can evaluate javascript code dynamic pages are not a disqualifier. – Frederic Klein Sep 29 '16 at 11:49
  • Are you talking about browser automation? If so http://www.seleniumhq.org/ may be what you're looking for. See also http://stackoverflow.com/questions/3422262/take-a-screenshot-with-selenium-webdriver. But I think you need to edit your question to make it clear how this will operate. – Daz Sep 29 '16 at 13:57
  • Thanks for your information Madan, Klein and Daz :) – Jason Isaac S Sep 29 '16 at 16:06

1 Answers1

0

The Selenium website has an example of how to do something similar to this from Java (using Firefox as the browser) at http://www.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example

Here's a quick TL;DR version. It doesn't click through to Stack Overflow but instead should take a screenshot of the Google results for that term. Going via Google when you already know the URL of the site may be a redundant step anyway, I am sure you can modify this example to make it do what you need it to.

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");

// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Stack Overflow");
element.submit();

// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver d) {
        return d.getTitle().toLowerCase().startsWith("Stack Overflow");
    }
});

// Screenshot of search results (screen not whole page)                                        
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshot.png"));

Screenshot code is from Sergii Pozharov's answer at Take a screenshot with Selenium WebDriver - see that for other considerations such as choice of driver.

Community
  • 1
  • 1
Daz
  • 2,833
  • 2
  • 23
  • 30