wait_for
parameter in ZenRows tells the scraper to pause until a specific CSS selector is found in the rendered HTML. This feature requires js_render
to be set to true
.
If ZenRows cannot find a matching element for the CSS selector, it will retry several times internally. If it still doesn’t match, the request will return a 422 error. This means your selector likely does not exist in the final HTML, or is too fragile to be reliable.
This guide helps you debug wait_for
failures and avoid common pitfalls.
wait_for
wait_for
parameter targets dynamic content that loads asynchronously. This includes content that appears after an AJAX call (a background request that updates part of a page without reloading) or JavaScript rendering. Here’s a typical usage:
wait_for
Inspect the site using browser DevTools
Verify your selector
document.querySelectorAll('your_selector')
in the browser consoleTips
.class
or #id
[data-testid="item"]
data-*
.original_status=true
allowed_status_codes=404,500
display: none
) js_instructions
to simulate a click or scroll action first.wait_for
selector that appears earlier in the loading process. Alternatively, switch to our Scraping Browser, which offers longer session times and allows you to manipulate requests more deeply through Puppeteer or Playwright.wait
parameter:
scrapingcourse.com/ecommerce/
, and your request fails with a 422 error while your wait_for
CSS selector is:
Selector | Example | Use Case |
---|---|---|
.class | .price | Wait for an elements with class “price” |
#id | #main-content | Wait for an element with ID “main-content” |
[data-attr] | [data-loaded="true"] | Wait for attribute presence |
[attr^="val"] | [id^="item-"] | Attribute starts with “item-” |
[attr$="val"] | [src$=".png"] | Attribute ends with “.png” |
A > B | .list > .item | Direct child of a parent |
A B | .list .item | Any descendant item inside a parent |
A, B | .price, .discount | Match either .price or .discount |
:nth-child(n) | li:nth-child(2) | Select the 2nd child (or any Nth) of its parent |
:first-child | div:first-child | First child of a parent element |
:last-child | div:last-child | Last child of a parent element |
Does this guide also work for XPath?
wait_for
parameter. Just make sure to provide a valid expression.Here’s an example based on the HTML below:$x('//your/xpath')
.