Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/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: /docs/k6/latest/using-k6-browser/recommended-practices/prevent-cookie-banners-blocking.md (append .md) or send Accept: text/markdown to /docs/k6/latest/using-k6-browser/recommended-practices/prevent-cookie-banners-blocking/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
Prevent cookie banners from blocking interactions
Cookie banners often appear shortly after a page loads or remain hidden until you interact with the page. Leaving a banner open can block page elements and cause interaction failures. For example, a button might not be clickable because the banner overlaps it. If you find yourself using force click frequently, the element is likely hidden or overlapped by a cookie banner.
To avoid these failures, trigger and dismiss the cookie banner early in the test flow.
- Trigger the banner: simulate a small user action, such as clicking or scrolling, immediately after navigation to reveal banners that appear only after interaction.
- Dismiss the banner: once the banner is visible, close or accept it before continuing with the rest of the test.
Example
The example below navigates to a page and clicks a button. Replace the placeholder steps with a click to an element on your website, or scrolling a page, that reveals and dismisses your site’s cookie banner.
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',
},
},
},
},
thresholds: {
checks: ['rate==1.0'],
},
};
export default async function () {
const page = await browser.newPage();
try {
await page.goto('https://quickpizza.grafana.com/');
// Click an element to trigger a cookie banner.
// Clicking an element also scrolls the page if the
// element is outside the frame.
const button = page.locator('button[name="pizza-please"]')
await expect(button).toBeEnabled();
await button.click();
// Dismiss the cookie banner
const cookieBannerButton = page.locator('button[name="dismiss-cookie"]')
await expect(button).toBeEnabled();
await button.click();
} finally {
await page.close();
}
}Was this page helpful?
Related resources from Grafana Labs

