Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/latest/javascript-api/jslib/testing/retrying-assertions/tobehidden.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/jslib/testing/retrying-assertions/tobehidden/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
toBeHidden()
The toBeHidden() method asserts that an element is hidden on the page. This is a retrying assertion that automatically waits for the element to become hidden.
Syntax
await expect(locator).toBeHidden();
await expect(locator).not.toBeHidden();
await expect(locator).toBeHidden(options);Parameters
| Parameter | Type | Description |
|---|---|---|
| options | RetryConfig | Optional configuration options |
Returns
| Type | Description |
|---|---|
| Promise | A promise that resolves when the assertion passes |
Description
The toBeHidden() method checks if an element is hidden on the page. An element is considered hidden if:
- It does not exist in the DOM
- It has zero dimensions
- It is hidden by CSS (
display: none,visibility: hidden, etc.) - It is outside the viewport bounds
This is a retrying assertion that will automatically re-check the element’s visibility until it becomes hidden 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/');
// Check that non-existent elements are hidden
await expect(page.locator('.error-message')).toBeHidden();
await expect(page.locator('.loading-spinner')).toBeHidden();
// Click the pizza button to show the recommendation
await page.locator('button[name="pizza-please"]').click();
// Wait for the recommendation to appear
await expect(page.locator('h2[id="pizza-name"]')).not.toBeHidden();
// Verify the button is no longer visible after clicking
await expect(page.locator('button[name="pizza-please"]')).toBeHidden();
}Was this page helpful?
Related resources from Grafana Labs

