# Common Playwright Errors and Quick Fixes ## Timeout Errors ### Error: "Timeout 30000ms exceeded waiting for selector" **Cause:** Element not found within timeout period **Quick Fixes:** ```typescript // 1. Add explicit wait await page.waitForSelector('[data-testid="element"]', { state: 'visible' }); // 2. Verify data-testid is correct const count = await page.locator('[data-testid="element"]').count(); console.log('Found', count, 'elements'); // 3. Wait for page to load first await page.waitForLoadState('domcontentloaded'); // 4. Increase timeout if legitimately slow await page.locator('[data-testid="element"]').waitFor({ state: 'visible', timeout: 60000 }); ``` ### Error: "Timeout 30000ms exceeded waiting for navigation" **Cause:** Page navigation taking too long or not happening **Quick Fixes:** ```typescript // 1. Wait for specific URL await page.waitForURL('/expected-path', { timeout: 45000 }); // 2. Wait for load state await page.waitForLoadState('networkidle'); // 3. Check if navigation actually occurs console.log('Current URL:', page.url()); ``` ## Selector Errors ### Error: "strict mode violation: locator resolved to X elements" **Cause:** Multiple elements match the selector **Quick Fixes:** ```typescript // 1. Use .first() or .last() await page.locator('[data-testid="item"]').first().click(); // 2. Use .nth() for specific element await page.locator('[data-testid="item"]').nth(2).click(); // 3. Make selector more specific (avoid if possible) await page.locator('[data-testid="item"][aria-selected="true"]').click(); // 4. Filter locators await page.locator('[data-testid="item"]').filter({ hasText: 'Active' }).click(); ``` ### Error: "Element not found" **Cause:** Element doesn't exist or wrong selector **Quick Fixes:** ```typescript // 1. Verify element exists const exists = await page.locator('[data-testid="element"]').count() > 0; console.log('Element exists:', exists); // 2. Check for typos in data-testid // Verify in HTML: