# Lazy loading

Handle lazy-loaded and late-rendering content in visual tests with wait-for-selector, delays, and timeouts.

If parts of a page load with a delay - data fetched from an API, images below the fold, charts rendered client-side - the capture can fire before they appear. The result is a snapshot with spinners or empty placeholders, and a diff on every run depending on what managed to load in time.

## Wait for selector

The most reliable fix: in the [suite settings](/docs/tests/visual-tests/suite-settings.md) (or on the affected snapshot), add a **Wait for selector** entry pointing at the element that appears last:

```
#dashboard-chart
//div[@class='loaded']
```

The capture waits until the element is present, so the snapshot always shows the fully rendered page. Prefer this over a fixed delay - it waits exactly as long as needed.

## Delay

When there is no reliable element to wait for (e.g. a fade-in animation after data arrives), add a **Delay** in milliseconds before the capture. Delays are a blunt instrument: too short and the flakiness stays, too long and every snapshot slows down. Scope them to the snapshots that need them.

## Timeout

The suite **Timeout** (default: `60` seconds) caps how long a capture can take, including wait-for-selector conditions. If heavy pages hit the cap, raise the timeout; the capture won't wait longer than that, so if a wait-for-selector never shows up, check that the selector matches the tested page.

## Scriptless captures

The [`bdy tests capture`](/docs/cli/tests/capture.md) command accepts the same controls, optionally scoped per domain:

```bash
bdy tests capture --sitemap https://example.com/sitemap.xml \
  --waitFor "CSS=#content" "example.com::XPATH=//div[@class='loaded']" \
  --delay "example.com::2000"
```


---
Original source: https://buddy.works/docs/tests/visual-tests/troubleshooting/lazy-loading