Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'Use Page.close to clean up test resources'
description: 'Use Page.close in your browser tests to ensure k6 properly flushes metrics and cleans up resources'
weight: 01
weight: 650
---

# Use Page.close to clean up test resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
---
title: 'Handling Stale or Dynamic Elements After Navigation'
title: 'Handle stale or dynamic elements after navigation'
description: 'Wait for elements to appear in k6 browser tests to avoid interacting with stale or dynamic content'
weight: 01
weight: 50
---

# How To Handle Stale or Dynamic Elements After Navigation
Modern websites often update the DOM asynchronously after navigation or user interactions. Waiting for navigation to complete is not sufficient, as test scripts may still fail or attempt to interact with elements that are not yet available. Instead, wait for specific elements to appear before continuing your test. Use [locator APIs](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/) such as `waitFor` to ensure elements are ready for interaction. This is especially important when testing SPAs or any pages with dynamic content, where elements may be added, removed, or updated asynchronously.
# Handle stale or dynamic elements after navigation

Modern websites often update the DOM asynchronously after navigation or user interactions. Waiting for navigation to complete isn't sufficient, as test scripts may still fail or attempt to interact with elements that aren't yet available.

To avoid these issues, wait for specific elements to appear before you continue your test. Use [locator APIs](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-browser/locator/) such as `waitFor` to ensure elements are ready for interaction.

This approach is especially important when you test single-page applications (SPAs) or any pages with dynamic content, where elements may be added, removed, or updated asynchronously.

## Example
{{< code >}}

```javascript
import { browser } from 'k6/browser';
Expand Down Expand Up @@ -36,5 +40,3 @@ export default async function () {
});
}
```

{{< /code >}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 'Hybrid approach to performance'
heading: 'Hybrid performance with k6 browser'
head_title: 'Hybrid performance with k6 browser'
description: 'An example on how to implement a hybrid approach to performance with k6 browser'
weight: 200
weight: 100
---

# Hybrid performance with k6 browser
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Prevent cookie banners from blocking interactions"
description: "How to reveal and dismiss cookie banners in k6 browser tests to prevent blocked interactions and improve test reliability."
weight: 100
weight: 350
---

# Prevent cookie banners from blocking interactions
Expand Down
Loading