Menu

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

Open source

Selection.serializeObject()

Encode a set of form elements as an object ({ "inputName": "value", "checkboxName": "value" }).

Returns

TypeDescription
objectObject representation of the matched form or form elements, key is field name and value is field value.

Example

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

export default function () {
  const content = `
 <form><input name="username"></form>
  `;

  const doc = parseHTML(content);
  const sel = doc.find('form');
  const serialized = sel.serializeObject();

  console.log(JSON.stringify(serialized)); // {"username": ""}

  sleep(1);
}