vitest-dev/vitest · error · Error
Method "elementLocator" is not supported by the
Error message
Method "elementLocator" is not supported by the "${provider}" provider. What it means
page.elementLocator converts a DOM Element into a Vitest Locator. The default page stub throws because building a Locator requires provider-specific binding (Playwright/WebDriverIO wrap the element in their own locator handles). The stub is replaced when a full provider's plugin calls page.extend or overrides the method directly.
Solutions
- Switch test.browser.provider to 'playwright' or 'webdriverio' so elementLocator returns a real Locator.
- Under preview, operate on the Element directly (e.g. assert on el.outerHTML or attributes) instead of converting to a Locator.
- Avoid passing raw Elements into expect() chains that require Locators.
Example fix
// before const loc = page.elementLocator(myEl) // preview throws // after (switch provider) // test.browser.provider = 'playwright' const loc = page.elementLocator(myEl)
Defensive patterns
Strategy: validation
Validate before calling
if (getBrowserState().provider === 'preview') {
// operate on the Element directly instead of converting to a Locator
} else {
page.elementLocator(myEl)
} Type guard
function supportsLocators(): boolean {
return ['playwright', 'webdriverio'].includes(getBrowserState().provider ?? '')
} Prevention
- Configure a full provider before using elementLocator.
- Avoid passing raw Elements into Locator-based assertion chains under preview.
- Document which assertions require Locators.
When it happens
Trigger: Calling page.elementLocator(el) while provider is 'preview'; using convertToLocator (which delegates to page.elementLocator) under preview; calling expect(element).toBeVisible() style assertions that internally resolve via elementLocator.
Common situations: Passing a raw Element to a Locator-based API under the preview provider; mixing Locator and Element APIs without a full provider; default provider config.
Related errors
- Method "frameLocator" is not supported by the
- Method "getByAltText" is not supported by the
- Method "getByLabelText" is not supported by the
- Method "getByPlaceholder" is not supported by the
- Method "getByRole" is not supported by the
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/00a6f19a556b976a.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/client/tester/context.ts:461
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.`)
},
frameLocator() {
throw new Error(`Method "frameLocator" is not supported by the "${provider}" provider.`)
},
extend(methods) {
for (const key in methods) {
(page as any)[key] = (methods as any)[key].bind(page)
}
return page
},
}
function convertToLocator(element: Element | Locator): Locator {
if (element instanceof Element) {
return page.elementLocator(element)
}
return element
}View on GitHub (pinned to 1fa9837ec2)