πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Questions
Question 61 of 100
Mechanics
Advanced

Can you disable auto-waiting? When would you?

The Answer

Yes. You can bypass auto-waiting by using `page.evaluate()` to run JavaScript directly, or `locator.dispatchEvent('click')`. You'd do this to simulate programmatic actions rather than real user interactions.

Deep Dive Explanation

Only disable auto-waiting when intentionally testing edge cases like: clicking a disabled button to verify nothing happens, triggering hidden programmatic event listeners, or testing that your app correctly handles events on overlapped elements. In production test suites, disabling auto-wait is almost always a red flag.

example.spec.ts
// Force click without actionability checks (bypasses auto-wait)
await page.locator('#hidden-trigger').dispatchEvent('click');

// Use JS evaluation to bypass all checks
await page.evaluate(() => {
  document.querySelector('#submit')?.click();
});

// waitFor with specific state (explicit, controlled)
await page.locator('#element').waitFor({ state: 'attached' }); // Just in DOM, not visible