JavaScript clicks required for headless mode execution?

I do this a lot - I don’t think it’s “less desirable” if (that’s a big IF) you know what you’re doing - read on…

That’s a ton of questions which I’ll answer together…

The number one issue with going the JavaScript route is inherent in the DOM element click API (i.e., it’s not JavaScript’s fault). Your click code (your click event) is applied to the element regardless of its availability. What does that mean?

  1. You can click an invisible element.
  2. You can click an element that is not visible in the viewport (it’s “off screen”).
  3. You can click on an element obscured by other elements (visible or not).
  4. Anything else you can think of…

All of which leads to this simple fact: your code can do things a user cannot do. You could pass a test that should fail.

And that’s why I said, “if you know what you’re doing”, above. If you take reasonable precautions to ensure the target element is “visible to a human” and is ready to receive clicks, I see no issue with using JavaScript when all other means at your disposal have failed to accomplish your goal.

It’s for this reason that the Katalon devs developed WebUI.enhancedClick – as a last resort, that API tries a JavaScript click if other methods fail.

Hope that helps…