AI Leaf Global Learn

Playwright: Test a Save Button That Starts Disabled

By AI Leaf Global Learn · 23 November 2026

Inspect a disabled-button test, verify the result and learn why a fixed sleep is not a reliable waiting strategy.

What should a browser test wait for?

A button may exist before it is enabled. A fixed sleep guesses when it will be usable; a test should instead target the user's action and verify its result. Playwright performs actionability checks before clicking. This exercise isolates one disabled-button case without submitting a real website form.

Self-contained practice test

This TypeScript example is intended for an installed Playwright Test practice project. It was reviewed against the official auto-waiting documentation but was not executed in this publishing run. Save it as disabled-save.spec.ts and run it in your approved local test environment.

import { test, expect } from '@playwright/test';

test('waits for enabled Save and checks the outcome', async ({ page }) => {
  await page.setContent(`
    <button disabled>Save</button>
    <p role="status">Not saved</p>
    <script>
      const button = document.querySelector('button');
      setTimeout(() => { button.disabled = false; }, 300);
      button.addEventListener('click', () => {
        document.querySelector('[role=status]').textContent = 'Saved';
      });
    </script>
  `);
  await page.getByRole('button', { name: 'Save', exact: true }).click();
  await expect(page.getByRole('status')).toHaveText('Saved');
});

Expected result: the test passes after Save becomes enabled and the status changes to Saved. No waitForTimeout is added to the test. The timer is deliberately part of the artificial page, simulating a page becoming ready; it is not the test's waiting strategy.

Why the assertion matters

A successful click is not proof that a record was stored. This artificial page only changes text. In an application test, assert the intended visible outcome and use an isolated backend/test account when checking persistence. Do not test by creating real admissions or payments.

Practise with a slower page

Change the simulated delay from 300 to 1200 milliseconds and rerun. Then remove the line that enables the button. Expected: the first change still allows the test to pass within its configured timeout; the second causes the click to time out. These modifications have not been executed here. Explain the difference without increasing a sleep.

Preparing for online learning across Tamil Nadu

Before requesting a testing-course demo, confirm your laptop can run the browser tooling and try this small isolated exercise. Bring the test file and failure message to the session. Ask how the trainer distinguishes a locator problem from an application state problem. This is useful preparation for learners joining online from Tamil Nadu; Tambaram is the admission enquiry contact, not a claim of branches elsewhere.

Limits

Auto-waiting does not decide whether your business process succeeded. Avoid forcing clicks to hide a disabled state. This example does not cover login, network failure, retries or database persistence.

Explore the Playwright course pathway and request a demo to confirm prerequisites and current online learning options. For another browser debugging boundary, read why an API can work outside a browser yet fail with CORS.

Official reference

Playwright auto-waiting and actionability

Continue learning

More Example Code guidesExplore courses