Menu
Open source
Selection.data([key])
Return the value at the named data store for the first element in the set of matched elements. Mimics jquery.data
Parameter | Type | Description |
---|---|---|
key (optional) | string | A string naming the piece of data to set. |
Returns
Type | Description |
---|---|
string | The value at the named data store. |
Example
JavaScript
import { parseHTML } from 'k6/html';
import { sleep } from 'k6';
export default function () {
const content = `
<h1 data-test-id="data-value">Hola</h1>
`;
const doc = parseHTML(content);
const sel = doc.find('h1');
console.log(sel.data().testID);
console.log(sel.data('test-id'));
console.log(sel.data('testId'));
sleep(1);
}
Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.