Hi. I would like to ask is it possible to script a HTML form submission if the fields contain only id and not the fields name?
Hi @wxxlum7
Welcome to the support forum
I understood your question as the following:
For an HTML form of the given shape:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
Would it be possible to submit it via k6, while selecting the field to fill based on a selector that points to their ids:
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
// Request page containing a form
let res = http.get('https://httpbin.test.k6.io/forms/post');
// Now, submit form setting/overriding some fields of the form
res = res.submitForm({
formSelector: 'form',
// we pass the value of the inputs id fields as keys
fields: { fname: 'test', lname: 'test2' },
});
sleep(3);
}
Unfortunately, as far as I know, this is not possible at the moment. As described in the documentation, only the input field names are supported.
If you’d like for k6 to also have the ability to target another HTML tag’s field such as id
, we’d really appreciate it if you would take the time to open an issue on the repository. We would gladly look into it.
Let me know if that was helpful
1 Like