{"record":{"id":"3efb7dec1fdcc4f1","repo":"apify/crawlee","slug":"selector-selector-not-found-3efb7d","errorCode":null,"errorMessage":"Selector '${selector}' not found.","messagePattern":"Selector '(.+?)' not found\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/linkedom-crawler/src/internals/linkedom-crawler.ts","lineNumber":315,"sourceCode":"                const urls = await extractLinks(options);\n\n                return addRequests(urls, {\n                    ...options,\n                    baseUrl,\n                    strategy: options.strategy ?? EnqueueStrategy.SameHostname,\n                });\n            },\n            async waitForSelector(selector: string, timeoutMs = 5_000) {\n                const $ = cheerio.load(crawlingContext.body);\n\n                if ($(selector).get().length === 0) {\n                    if (timeoutMs) {\n                        await sleep(50);\n                        await this.waitForSelector(selector, Math.max(timeoutMs - 50, 0));\n                        return;\n                    }\n\n                    throw new Error(`Selector '${selector}' not found.`);\n                }\n            },\n            async parseWithCheerio(selector?: string, _timeoutMs = 5_000) {\n                const $ = cheerio.load(crawlingContext.body);\n\n                if (selector && $(selector).get().length === 0) {\n                    throw new Error(`Selector '${selector}' not found.`);\n                }\n\n                return $;\n            },\n        };\n    }\n}\n\n/**\n * Extracts URLs from a given Window object.\n * @ignore","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/linkedom-crawler/src/internals/linkedom-crawler.ts#L297-L333","documentation":"waitForSelector polls the linkedom DOM for an element matching `selector` every 50ms until the timeout elapses. If the selector still matches nothing when the remaining timeout reaches zero, the crawler gives up and throws 'Selector ... not found.' It signals that the awaited element never appeared in the parsed document.","triggerScenarios":"Calling `context.waitForSelector(selector)` (with default or explicit timeout) in a LinkedomCrawler handler when the parsed body contains no element matching the selector after the full timeout.","commonSituations":"Waiting for client-side-rendered content that linkedom (a static DOM, no JS execution) will never produce; typos in CSS selectors; content behind login/consent walls; waiting on elements loaded by XHR after initial HTML parse.","solutions":["Verify the selector against the actual HTML (`document.querySelector` in the browser devtools or by logging `context.body`).","Remember linkedom does not execute JavaScript: if the element is rendered client-side, use PlaywrightCrawler instead of LinkedomCrawler.","Catch the error and treat the element as optional, or wrap waitForSelector in try/catch with a fallback parse.","Check for bot-protection or consent interstitials replacing the expected content and handle those pages separately."],"exampleFix":"// before\nawait context.waitForSelector('.product-price');\n\n// after\ntry {\n    await context.waitForSelector('.product-price');\n} catch {\n    log.warning('Product price not found on page, skipping.');\n    return;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    await context.waitForSelector('.target', 5000);\n} catch (err) {\n    if (err.message.includes('not found')) {\n        log.warning('Selector .target never appeared; continuing without it.');\n    } else {\n        throw err;\n    }\n}","preventionTips":["Verify selectors against the actual HTML (log context.body or check in devtools) before waiting on them.","Do not use linkedom for pages that require JavaScript to render the awaited element; use PlaywrightCrawler.","Treat optional elements with try/catch instead of hard waits.","Account for consent walls / bot-protection pages that replace expected content."],"tags":["selector","dom","timeout","crawler"],"backgroundTag":"selector-not-found","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}