JavaScript clicks required for headless mode execution?

I am developing web UI tests in Katalon and have had solid success executing test in GUI mode with browsers on my local machine. When running the same tests in Headless mode however, the tests often fail for reasons like ‘element intercepted’ or ‘element not interactable’. All of my research thus far has led me to believe that inserting JavaScript clicks at these failing steps will help, and it usually has solved the issues.
My issue now is over time, I am slowly converting all of my ‘Click’ keywords to JavaScript clicks across my test cases. This feels like it makes the use of Katalon as a whole a lot less desirable for web UI testing.
Just curious if anyone has any feedback on this? Am I wrong in converting Katalon ‘Click’ keywords to JavaScript clicks when I receive these errors in Headless mode? Is there still value in using Katalon even if their ‘Click’ keyword fails frequently in headless mode? Is there a better way to manage this?

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…

this reply helps a lot! I actually did not know about the Enhanced Click keyword and am trying that now. I am surprised that didn’t turn up previously in my searches. Also I really appreciate the examples of reasons why I may be having these issues so I have some concrete suggestions to bring to my co-workers on the dev team. Appreciate it!

1 Like