k6

A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Documentation

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Selection (k6/html)

New Selection()

Represents a set of nodes in a DOM tree.

Selections have a jQuery-compatible API, but with two caveats:

  • CSS and screen layout are not processed, thus calls like css() and offset() are unavailable.
  • DOM trees are read-only, you can't set attributes or otherwise modify nodes.

(Note that the read-only nature of the DOM trees is purely to avoid a maintenance burden on code with seemingly no practical use - if a compelling use case is presented, modification can easily be implemented.)

Method
Description

Find the selection descendants, filtered by a selector.

Get the value of an attribute for the first element in the Selection.

Get the text content.

Get the HTML contents of the first element in the set of matched elements.

Get the current value of the first element in the set of matched elements.

Retrieve the Element (k6/html) matched by the selector.

Reduce the set of matched elements to those that have a descendant that matches the selector.

Get the first element that matches the selector by testing the element itself and traversing up through its ancestors.

Remove elements from the set of matched elements.

Get the immediately following sibling of each element in the set of matched elements

Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.

Get the immediately preceding sibling of each element in the set of matched elements.

Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.

Get the parent of each element in the current set of matched elements, optionally filtered by a selector.

Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.

Get all preceding siblings of each element up to but not including the element matched by the selector.

Get all following siblings of each element up to but not including the element matched by the selector.

Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector.

Return the number of elements in the Selection.

Reduce the set of matched elements to the first in the set.

Reduce the set of matched elements to the final one in the set.

Get the children of each element in the set of matched elements, including text and comment nodes.

Reduce the set of matched elements to the one at the specified index.

Get the children of each element in the set of matched elements, optionally filtered by a selector.

Reduce the set of matched elements to those that match the selector or pass the function's test.

Check the current matched set of elements against a selector or element and return true if at least one of these elements matches the given arguments.

Iterate and execute a function for each matched element.

Pass each element in the current matched set through a function, producing a new Array containing the return values.

Reduce the set of matched elements to a subset specified by a range of indices.

Retrieve all the elements contained in the Selection, as an array.

Return the value at the named data store for the first element in the set of matched elements.

import {parseHTML} from "k6/html";
import http from "k6/http";

export default function() {
  const res = http.get("https://loadimpact.com");
  const doc = parseHTML(res.body);
  const pageTitle = doc.find('head title').text();
  const langAttr = doc.find('html').attr('lang');
};

Selection (k6/html)