Menu

This is documentation for the next version of K6. For the latest stable release, go to the latest version.

Documentationbreadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/httpbreadcrumb arrow Responsebreadcrumb arrow Response.clickLink( [params] )
Open source

Response.clickLink( [params] )

Create and make a request corresponding to a link, found in the HTML of response, being clicked. By default it will look for the first a tag with a href attribute in the HTML, but this can be overridden using the selector option.

This method takes an object argument where the following properties can be set:

ParamTypeDescription
selectorstringA selector string passed to Selection.find(selector) to locate the link to click. By default this is "a[href]".
paramsobjectA Params object that will be forwarded to the link click request. Can be used to set headers, cookies etc.

Returns

TypeDescription
ResponseThe link click response

Example

JavaScript
import http from 'k6/http';

export default function () {
  // Request page with links
  let res = http.get('https://httpbin.test.k6.io/links/10/0');

  // Now, click the 4th link on the page
  res = res.clickLink({ selector: 'a:nth-child(4)' });
}