ScreenshotNeo

BlogHow-to

Screenshot Indian Ecommerce Search Result Pages in Java Playwright

Capture full Indian ecommerce search pages or individual results with Java Playwright, choose repeatable screenshot settings, and understand access limits.

By the ScreenshotNeo team4 October 20267 min read

Use Playwright Java’s Page.screenshot to save a search-results page, and set fullPage to capture its full scrollable height. Use Locator.screenshot when you need just one product result. The code below is for a page or fixture you are authorized to automate: Playwright’s screenshot API does not grant permission to automate Amazon.in, Flipkart, or any other marketplace.

1. Set up a Java Playwright screenshot

The examples use Playwright’s Java API. Add the Playwright dependency and install the browser binaries using the instructions for your project in the official Playwright Java documentation. Then create a browser, open an authorized target page, and save the capture.

import com.microsoft.playwright.*;
import java.nio.file.Paths;

public class SearchScreenshot {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch(
          new BrowserType.LaunchOptions().setHeadless(true));
      Page page = browser.newPage(new Browser.NewPageOptions()
          .setViewportSize(1440, 1000));

      page.navigate("https://your-authorized-test-page.example/search?q=shoes");
      page.screenshot(new Page.ScreenshotOptions()
          .setPath(Paths.get("search-results.png"))
          .setFullPage(true));

      browser.close();
    }
  }
}

Replace the example host with a page you own, a test fixture, or a destination for which you have permission. The screenshot API saves the current page image; setFullPage(true) expands the capture to the full scrollable page. You can also omit setPath and use the returned byte[] for image processing or storage.

2. Wait for results and capture a single result

Search pages often render results after navigation. Wait for a meaningful result container before capturing, rather than relying on a fixed sleep. Use locators grounded in accessible roles or stable identifying attributes where possible. The selector below is illustrative; the dossier does not establish any live marketplace selector.

import com.microsoft.playwright.*;
import java.nio.file.Paths;

public class OneResultScreenshot {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().launch();
      Page page = browser.newPage(new Browser.NewPageOptions()
          .setViewportSize(1365, 900));
      page.navigate("https://your-authorized-test-page.example/search?q=shoes");

      Locator results = page.locator("[data-testid='search-results']");
      results.waitFor();
      Locator result = results.locator("[data-testid='product-card']")
          .filter(new Locator.FilterOptions().setHasText("Example product"))
          .first();
      result.screenshot(new Locator.ScreenshotOptions()
          .setPath(Paths.get("one-result.png")));

      browser.close();
    }
  }
}

A locator screenshot captures the matched element’s bounds. If the element itself is scrollable, the image contains only its currently visible scrolled content. If several cards match, narrow the locator using a stable child, accessible text, or an appropriate test ID, and explicitly choose the intended match.

3. Choose screenshot settings for useful comparisons

Option What it changes When to use it
fullPage Captures the full scrollable page rather than only the viewport. Reviewing overall layout or the complete result sequence.
clip Restricts output to a rectangle. Comparing a known region with consistent coordinates.
scale Chooses CSS-pixel or device-pixel output. Keeping image dimensions consistent across device scale settings.
type Selects PNG, JPEG, or WebP output. PNG for lossless visual review; JPEG or WebP when smaller files matter.
mask Covers the bounds of selected locators. Concealing or neutralizing dynamic regions in a permitted test capture.
style Applies screenshot-only CSS. Hiding or stabilizing elements that otherwise vary between captures.
animations Controls CSS and Web Animations during capture. Disabling animations for more repeatable visual comparisons.

Use Page.ScreenshotOptions for page captures and Locator.ScreenshotOptions for element captures; both expose screenshot controls. For example:

page.screenshot(new Page.ScreenshotOptions()
    .setPath(Paths.get("results.webp"))
    .setType(ScreenshotType.WEBP)
    .setFullPage(true)
    .setScale(ScreenshotScale.CSS)
    .setAnimations(ScreenshotAnimations.DISABLED));

For a crop, set a clip rectangle with the desired x/y origin and width/height. A clip is coordinate based, so keep viewport and page state stable before using it. Masks and screenshot styles help reduce visual noise, but should not hide content that matters to the comparison.

4. Keep Indian search result captures comparable

Marketplace results can include sponsored placements alongside organic results. A 2024 study of sampled Amazon.in and Flipkart grid-based search result pages reported that 11.7% of ad spaces across sampled Amazon result pages, and 15.16% on sampled first Amazon result pages, were occupied by Amazon private-label products. Its survey included 68 participants. These figures describe that study’s collected snapshots, not current marketplace measurements. Preserve the query and labels/positions needed to distinguish sponsored from organic results when that distinction matters. Study source on arXiv.

For repeatable comparisons, keep constant or record the marketplace, query, viewport dimensions, device scale, page state, region captured, capture time, and whether you captured the whole page or a single result. Save this metadata next to the image; a stable filename can include a sanitized query and timestamp. This is useful for later interpretation, but does not make an otherwise unauthorized capture permissible.

5. Access and permission limits

The Amazon India Site Terms returned in the research state restrictions that include use of “data mining, robots, or similar data gathering and extraction tools.” Flipkart’s Terms of Use restrict use of page-scraping and other automated means to access, acquire, copy, or monitor website content. Read the current terms and obtain the required permission before automating a live marketplace. Use an authorized test page or fixture when you only need to validate screenshot code.

Playwright documents how to take screenshots; its API documentation does not establish permission for a particular marketplace workflow. The terms can change, and this guide does not establish an exception, API entitlement, or authorization for any specific use. Amazon India Site Terms · Flipkart Terms of Use.

6. Troubleshooting

Symptom Likely cause Fix
Screenshot is blank or missing results Capture happened before the result region rendered, or navigation did not reach the expected page state. Wait for a locator that represents the expected results, then capture. Check navigation and page errors in the authorized environment.
Locator matches nothing The selector is wrong, unstable, or not present in the current page state. Inspect your own fixture or permitted page; prefer role, text, label, placeholder, alt text, or test ID locators. Do not assume an example selector works on a marketplace.
Element image contains only part of a card The matched element is internally scrollable. Capture the relevant parent or page, or scroll the element to the desired position before taking its screenshot.
Images or lower results are absent Lazy-loaded resources have not appeared yet or full-page capture does not reflect the intended loaded state. Scroll through the authorized test page as needed and wait for expected content before capture; use a locator wait for the relevant result region.
Images differ between runs Animations, dynamic content, viewport, locale, or page state vary. Fix viewport and state, disable animations, apply a screenshot-only style or mask to irrelevant changing regions, and retain capture metadata.
Output is unexpectedly large or soft Image format or scale differs from expectations. Choose PNG/JPEG/WebP deliberately and set scale consistently. Compare output dimensions and quality on your own representative fixture.
Browser launch fails Required Playwright browser binaries are not installed or the runtime environment cannot launch the selected browser. Install the browser binaries using the official Java setup instructions and check the environment’s browser dependencies.

7. Performance, reliability, and storage

Full-page images grow with page height and pixel scale, so they generally require more time, memory, and storage than a single element capture. Capture only the region needed, select a suitable output type, and avoid unnecessarily large viewport or device scale settings. These are implementation considerations; no benchmark is asserted here.

For reliable comparisons, make navigation and readiness conditions explicit, use stable locators, and control animations and viewport. A fixed delay can be useful for a known timed behavior, but locator-based waiting is usually more tied to the page condition you need. Keep the screenshot bytes or file together with query, time, viewport, and page-state notes if the image will be reviewed later.

8. Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns a PNG, JPEG, WebP, or PDF. Its capture flow accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status. An MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs.

For a permitted public page, the simple call looks like this. See the ScreenshotNeo API documentation for parameters and configuration.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo offers 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000. Every feature is on every plan. The service does not grant permission to capture a marketplace page: use it only for URLs you are authorized to capture. Sign up for 1,000 free screenshots a month, with no card.

9. FAQ

Can I save the screenshot as bytes instead of a file?

Yes. The Java screenshot API returns a byte[], which you can pass to downstream processing or storage instead of setting a path.

Does a full-page screenshot include every result that could load later?

It captures the page’s scrollable area at capture time. Wait for the content relevant to your use case and account for lazy loading before capturing.

Can I use this method for live Amazon.in or Flipkart pages?

The API capability alone does not authorize that use. Check the current terms and obtain permission; the cited terms restrict automated gathering.