GoError: no form found for selector 'form' in response

I’m trying to load test a form using K6. I have used K6 for rest, XML, website URL, but have not done that of form. This is my first time of trying to use K6 to load test HTML forms.
I tried to follow the example provided but always getting this error.

Error that I’m getting

ERRO[0003] GoError: no form found for selector ‘form’ in response ‘https://vpn.wesite.com:1234/caps/tes?URL=domain&strTitle=applyRule
at reflect.methodValueCall (native)-
at file:///C:/Users/GEGE/Documents/project/k6/submit-form.js:11:23(18) executor=per-vu-iterations scenario=default source=stacktrace

The form name (findMatch) is what I’m using as the selector, and I’m using the field id (acctNo)

Modified example code

import http from ‘k6/http’;
import { sleep } from ‘k6’;

export default function () {
// Request page containing a form
let res = http.post(‘https://vpn.wesite.com:1234/caps/tes?URL=domain&strTitle=applyRule’);

// Now, submit form setting/overriding some fields of the form
res = res.submitForm({
formSelector: ‘findMatch’,
fields: { acctNo: ‘1300000823’ },
});
sleep(3);
}

How do I make this work, please? Time is fastly running against me on this.

Hi there,

so the error means that there were no form elements found in the response. I would try a few things in your case:

  • Inspect the response body with k6 run --http-debug=full and make sure the form exists in the response.

  • The formSelector value should be a valid CSS selector. I’m confused by the error you’re getting since your example shows findMatch but the error says selector 'form'. In any case, findMatch is not a valid CSS selector. This should be an HTML element name, an element ID, class name, etc.

    The CSS selection library k6 uses is GitHub - andybalholm/cascadia: CSS selector library in Go , and you can read more about selectors here.

  • Alternatively, you might find it easier to avoid parsing the HTML and using the submitForm() API and just POST directly to the endpoint that’s expecting the form data. You can do this with plain http.post() as objects will be serialized to application/x-www-form-urlencoded, or for advanced uses with the recently added FormData polyfill.

Hope this helps,

Ivan

Thanks, @imiric , you’re always at hand to help. I sincerely appreciate this. I’m sorry I misplaced the name of the form, the actual name is findMatch, but I mistakenly added form in my post added to this community. I used both names and it returned the same result.

Like you said, I used the form name, and the element ID, and got the same error response. I’ll try the CSS Selector name, and see hope it goes.

Thanks a lot.

Thanks, @imiric , finally I am able to get it done by just passing the parameters vis the URL. It’s simple like making a normal call.

import http from ‘k6/http’;
import { sleep } from ‘k6’;

export default function () {
http.get(’‘https://vpn.wesite.com:1234/caps/tes?URL=domain&strTitle=applyRule&accountID=“1300000823”’);
sleep(1);
}