Is there a way to trigger 'force click' action?

Hi k6 Team,

Is there a way to trigger ‘force click’ action? or other workaround to click deep elements?

Currently, experiencing error as below since it was not ‘click’-ed
ERRO[0030] clicking on element: waiting for element state: context canceled

Used line of code:
page.$('a[id="id_here"]').click();

Any help is much appreciated, thanks!

Hi there, welcome to the forum :slight_smile:

Can you share a full minimal script that reproduces your issue?

Is the a element obscured by another element, so that it’s not visible to click on it? I.e. this behavior described by Playwright?

If so, the same force: true option should work in xk6-browser. You can also try the dispatchEvent('click') variant.

I’m not sure if we’re handling the option correctly, so if you’re still having issues, please create a GitHub issue, and we’ll look into it. If you can provide a fully working script that reproduces it, that would help. Along with your xk6-browser, OS and Chromium versions.

In the meantime, you should be able to work around it by clicking in a page.evaluate() call. That evaluates JS on the browser, so you can do:

page.evaluate(() => {
  document.querySelector('a[id="id_here"]').click();
});

@imiric thanks so much for your help, will try these options and feedback :pray:

Both page.evaluate() call and dispatchEvent('click') variant works like a gem. Awesome!