Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

Selection.single(selector)

Returns at most one element matching the selector, as a Selection object. It’s backed by goquery’s Single matcher, which is faster than find() when you only need the first match.

ParameterTypeDescription
selectorstringA string containing a selector expression to match elements against.

Returns

TypeDescription
SelectionSelection object.

Example

JavaScript
import { parseHTML } from 'k6/html';
import http from 'k6/http';

export default function () {
  const res = http.get('https://k6.io');
  const doc = parseHTML(res.body);

  const title = doc.single('h1').text();
}