Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/javascript-api/jslib/testing/retrying-assertions/tobeempty.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/jslib/testing/retrying-assertions/tobeempty/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
toBeEmpty()
The toBeEmpty() method asserts that an element is empty. It automatically retries the assertion until the element becomes empty or the timeout is reached.
Syntax
await expect(locator).toBeEmpty();
await expect(locator).not.toBeEmpty();
await expect(locator).toBeEmpty(options);Parameters
| Parameter | Type | Description |
|---|---|---|
| options | RetryConfig | Optional configuration options |
Returns
| Type | Description |
|---|---|
| Promise | A promise that resolves when the assertion passes |
Description
The toBeEmpty() method checks if an element is empty. An element is considered empty if:
- For input elements: the value is an empty string (
"") - For other elements: the text content is empty (no visible text)
This method automatically retries the assertion until the element’s content becomes empty or the timeout is reached.
Usage
import { browser } from 'k6/browser';
import { expect } from 'https://jslib.k6.io/k6-testing/0.6.1/index.js';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
}
};
export default async function () {
const page = await browser.newPage();
await page.goto('https://quickpizza.grafana.com/');
// Click on the advanced checkbox
await page.locator('label div').click();
// Check that an input field is empty
await expect(page.locator('#pizza-name')).toBeEmpty();
// Fill input and then verify it's not empty
await page.locator('#pizza-name').fill('my pizza');
await expect(page.locator('#pizza-name')).not.toBeEmpty();
}Was this page helpful?
Related resources from Grafana Labs

