This is documentation for the next version of K6. For the latest stable release, go to the latest version.
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
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);
}