vitest-dev/vitest · error · Error

Method "getByLabelText" is not supported by the "${provider}

Error message

Method "getByLabelText" is not supported by the "${provider}" provider.

What it means

page.getByLabelText is a throwing stub (packages/browser/src/client/tester/context.ts:442-443). The page-level label query is not implemented by default; label-text queries live on Locator instances (getElementLocatorSelectors wires locator.getByLabelText at context.ts:515). Calling it directly on page throws with the active provider name.

Source

Thrown at packages/browser/src/client/tester/context.ts:443

      }
      if (!hasActiveTrace) {
        return Promise.resolve()
      }
      return triggerCommand(
        '__vitest_markTrace',
        [{
          name,
          stack: bodyOrOptions?.stack ?? error?.stack,
        }],
        error,
      )
    })
  },
  getByRole() {
    throw new Error(`Method "getByRole" is not supported by the "${provider}" provider.`)
  },
  getByLabelText() {
    throw new Error(`Method "getByLabelText" is not supported by the "${provider}" provider.`)
  },
  getByTestId() {
    throw new Error(`Method "getByTestId" is not supported by the "${provider}" provider.`)
  },
  getByAltText() {
    throw new Error(`Method "getByAltText" is not supported by the "${provider}" provider.`)
  },
  getByPlaceholder() {
    throw new Error(`Method "getByPlaceholder" is not supported by the "${provider}" provider.`)
  },
  getByText() {
    throw new Error(`Method "getByText" is not supported by the "${provider}" provider.`)
  },
  getByTitle() {
    throw new Error(`Method "getByTitle" is not supported by the "${provider}" provider.`)
  },
  elementLocator() {
    throw new Error(`Method "elementLocator" is not supported by the "${provider}" provider.`)

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Resolve via a Locator: page.elementLocator(document.body).getByLabelText('Email').
  2. Register an extension: browser.locators.extend({ getByLabelText: (text, opts) => page.elementLocator(document.body).locator(getByLabelSelector(text, opts)) }).
  3. Use vitest/browser's locator helpers (getByLabelSelector from ivya) to build the selector.

Example fix

// before
const input = page.getByLabelText('Email')
// after
const input = page.elementLocator(document.body).getByLabelText('Email')
Defensive patterns

Strategy: type-guard

Validate before calling

const root = page.elementLocator(document.body)
const input = root.getByLabelText('Email')

Prevention

When it happens

Trigger: Calling page.getByLabelText('Email') on the page object without registering an extension or going through a Locator.

Common situations: Porting @testing-library/react getByLabelText usage into Vitest Browser; assuming page mirrors Playwright/WebdriverIO page APIs.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/c359b485f110b8b8.json. Report an issue: GitHub.