Selector Parameter

The selector parameter allows you to capture a specific element on the page instead of the entire viewport.

Specifications

PropertyValue
Typestring
RequiredNo
Defaultnull
APIScreenshot API only

Description

The selector parameter:

  • Uses CSS selectors to target specific elements
  • Captures only the selected element and its children
  • Preserves the element’s styles and layout
  • Useful for capturing specific components or sections

The selector must match exactly one element on the page. If multiple elements match or no elements are found, the API will return an error.

Examples

Basic Element Selection

{
    "url": "https://example.com",
    "selector": "#main-content"
}

Complex Selector

{
    "url": "https://example.com",
    "selector": ".article-container .content:first-child",
    "dpi": 2
}

Combining with Other Parameters

{
    "url": "https://example.com",
    "selector": ".product-card",
    "css": ".product-card { border: 2px solid blue; }",
    "webhook_url": "https://your-domain.com/webhook"
}

Common Selectors

Here are some commonly used selector patterns:

SelectorDescriptionExample
#idSelect by ID”#header”
.classSelect by class”.content”
tagSelect by tag name”main”
[attr]Select by attribute”[data-section=‘hero’]“
CombinedMultiple selectors”.container .card:first-child”

Best Practices

  1. Use Specific Selectors

    • Prefer IDs when possible
    • Use unique class combinations
    • Avoid overly complex selectors
  2. Verify Element Existence

    • Ensure the selector matches exactly one element
    • Test with different page states
    • Handle dynamic content appropriately
  3. Consider Layout

    • Check element positioning
    • Account for responsive designs
    • Test different viewport sizes

The selector parameter only works with the Screenshot API. For the HTML API, structure your HTML to include only the content you want to capture.

For dynamic websites, ensure the selected element is fully loaded before capture by using appropriate wait conditions in your implementation.