---
title: "HTML Forms | Grafana k6 documentation"
description: "Scripting example on how to handle HTML forms in a k6 test."
---

# HTML Forms

Scripting example on how to handle HTML forms.

In many cases using the [Selection](/docs/k6/latest/javascript-api/k6-html/selection/) API (jQuery API clone) to interact with HTML data is enough, but for some use cases, like with forms, we can make things easier providing a higher-level API like the [Response.submitForm( \[params\] )](/docs/k6/latest/javascript-api/k6-http/response/response-submitform/) API.

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import http from 'k6/http';
import { sleep } from 'k6';

export default function () {
  // Request page containing a form
  let res = http.get('https://quickpizza.grafana.com/admin');

  // Now, submit form setting/overriding some fields of the form
  res = res.submitForm({
    formSelector: 'form',
    fields: { username: 'admin', password: 'admin' },
  });
  sleep(3);
}
```

**Relevant k6 APIs**:

- [Response.submitForm(\[params\])](/docs/k6/latest/javascript-api/k6-http/response/response-submitform/)
- [Selection.find(selector)](/docs/k6/latest/javascript-api/k6-html/selection/selection-find/) (the [jQuery Selector API](http://api.jquery.com/category/selectors/) docs are also a good resource on what possible selector queries can be made)
