How to Enable a Button After Checking a Checkbox in Cypress
Use Cypress .check(), re-query the button, and assert its enabled state without fixed waits or flaky detached-element errors.

The reliable Cypress pattern is to check the checkbox, query the button again, assert that it is enabled, and then click it:
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').should('be.enabled').click()
.check() updates a checkbox through Cypress’s interaction model. The separate button query matters because a framework can replace the button during a re-render. Cypress retries the enabled-state assertion until it passes or the command times out, so a fixed sleep is unnecessary.
1. A complete Cypress test
Assume the application renders a native checkbox and a submit button:
<label>
<input type="checkbox" data-cy="terms" />
I agree to the terms
</label>
<button type="submit" data-cy="submit" disabled>Continue</button>
A test can verify the initial state, perform the interaction, and prove the transition:
describe('terms acceptance', () => {
it('enables Continue after the checkbox is checked', () => {
cy.visit('/checkout')
cy.get('[data-cy=submit]').should('be.disabled')
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]')
.should('be.enabled')
.click()
})
})
Cypress documents .check() for checkbox controls and the be.enabled and not.be.disabled assertions for native form controls.
2. Why the assertion waits correctly
Cypress links queries and assertions and retries the chain while the application settles. If a change handler, state update, or framework render enables the button a moment after the checkbox event, should('be.enabled') waits for that state until the command timeout.
This is preferable to cy.wait(500): the test proceeds as soon as the required state exists and fails with a useful assertion if it never arrives. See Cypress’s retry-ability guide for the command and assertion behavior.
3. Useful variants
Assert without clicking
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').should('be.enabled')
Use the negated disabled assertion
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').should('not.be.disabled')
Both forms test the native disabled property. Choose the wording that best describes the behavior your test is proving.
Let click perform its built-in actionability wait
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').click()
.click() waits for a native form control to become actionable, including the disabled property clearing. Keep the explicit assertion when the enabled transition is itself an acceptance criterion or when the failure should identify that state directly. Cypress documents these checks in its click actionability documentation.
Check a particular checkbox
cy.get('[data-cy=terms]').check({ force: false })
Use the default actionability checks whenever possible. If the checkbox is genuinely covered or outside the visible area, fix the application or test setup first; use force: true only when bypassing those checks is intentional.
4. Native disabled and aria-disabled are different
A native button such as <button disabled> has a disabled property that Cypress actionability understands. A control with only aria-disabled="true" is not natively disabled, so .click() does not treat it the same way.
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=next]')
.should('not.have.attr', 'aria-disabled', 'true')
.click()
If the application uses aria-disabled, assert the attribute explicitly. Also ensure the click handler refuses activation while the attribute is true; ARIA communicates state but does not disable browser behavior by itself.
5. Selectors that stay reliable
Prefer stable application selectors such as data-cy or data-testid. Avoid selectors based on changing text, CSS classes used only for styling, or a page-wide button query that can match several controls.
cy.get('[data-cy=checkout-form]').within(() => {
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').should('be.enabled').click()
})
If a selector can match multiple elements, narrow it with a form container, role, or a more specific test attribute before asserting the state.
6. Avoid detached-element failures
Do not keep a subject across an action that can trigger a render replacement:
// More fragile when the framework replaces the button node
cy.get('[data-cy=submit]').as('submit')
cy.get('[data-cy=terms]').check()
cy.get('@submit').should('be.enabled').click()
Instead, query the button after checking the box:
cy.get('[data-cy=terms]').check()
cy.get('[data-cy=submit]').should('be.enabled').click()
Cypress’s retry-ability guidance and detached-subject documentation explain why a fresh query is safer after DOM replacement.
7. Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The button remains disabled | The handler is not listening for the checkbox change, the wrong checkbox is selected, or validation has another unmet condition. | Confirm the selector, inspect the checkbox’s change/input handling, and assert each prerequisite separately. |
| Detached element error | The framework removed and recreated the button during re-rendering. | Split the chain and re-query the button after .check(). |
| The click happens while the UI appears disabled | The UI uses aria-disabled instead of native disabled. |
Assert not.have.attr for aria-disabled and make the application’s handler enforce the state. |
Flaky test with cy.wait(500) |
The delay is shorter than some runs and longer than necessary in others. | Replace it with .should('be.enabled') or a specific application readiness assertion. |
| Assertion fails because multiple buttons match | The selector is too broad. | Use a stable data-cy value or scope the query with .within(). |
.check() cannot interact with the checkbox |
The checkbox is hidden, covered, disabled, or not a checkbox input. | Correct the page state or selector; only use force: true when bypassing actionability is deliberate. |
8. Timing, reliability, and maintainability
- Use state assertions instead of arbitrary delays.
- Keep the checkbox and button queries separate when a render can replace nodes.
- Assert the initial disabled state when that is part of the requirement.
- Test the actual contract: native
disabledfor form controls or an explicitaria-disabledtransition for custom controls. - Keep selectors independent of visual styling so refactoring CSS does not break the test.
The default Cypress command timeout applies to the retried assertion. If the application legitimately takes longer, configure the timeout narrowly for that assertion rather than adding a global sleep:
cy.get('[data-cy=submit]', { timeout: 10000 })
.should('be.enabled')
.click()
9. Or skip the browser setup
If you need a screenshot of the resulting page for a test artifact, review, or documentation, ScreenshotNeo can capture it with one request. Its consent handling accepts cookie banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; and response headers identify the page verdict and whether it was billed. It also provides an MCP server for AI agents such as Claude and Cursor.
See the ScreenshotNeo API documentation for all options.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://example.com/checkout \
-o checkout.webp
Python
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com/checkout"},
timeout=90,
)
r.raise_for_status()
open("checkout.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.com/checkout'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
require('fs').writeFileSync('checkout.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo has 1,000 screenshots a month free with no card. Paid plans start at $5 for 3,000 shots, and every feature is included on every plan. Create a free ScreenshotNeo account.
10. FAQ
Should I use be.enabled or not.be.disabled?
They express the same native-control state. Use the wording that makes the expected behavior clearest.
Do I need cy.wait() after .check()?
No. A retried state assertion waits for the application update without guessing a delay.
Why does my button still look disabled after the assertion passes?
The visual style may be controlled by a class or ARIA attribute while the native property is enabled. Assert the state your application actually uses and test styling separately if it matters.
Can I chain the button query directly after .check()?
Yes, but a new cy.get() is clearer and protects the test when a framework replaces the button node during rendering.


