Issue with clicking on button using JavaScript

I have created the following keyword:
def click(String testObject){

    WebElement element = WebUiCommonHelper.findWebElement(findTestObject(testObject),30)

    WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))

I have been using it on multiple objects throughout my application to click on items and everything works just fine. Recently, I tried to use it to click on certain menu drop-down items, but for some reason it won’t make a click.
The log says that the step is PASSED and so my test fails on the next step because obviously it really didn’t click on the item. When I watch the test case being executed in browser, I can also see that there is in fact no click being made although the log says that it PASSED and so it fails on the next step.
Clicking on the menu item works with command in browser mode, but I cannot use it because, when running my test headless with Task Scheduler, it gives me the other element would receive click error.

What could be the issue?

WebUI is convinced it clicked something.

It’s probably clicking something other than the thing you expect it to click. Are you sure your TestObject is the correct element?

That’s a question of timing. I’ll place a callout to @Mate_Mrse though – he’s done more with headless than I have.

Default window size in headless mode is 800x600, so that might be the reason for the other-element-would-receive-click.

You can set the size here:

1 Like

Overall, changing the window size in headless resolved my problem. Thank you for that!

Still wondering tho, why doesn’t the JavaScript method actually make the click even though it says it does. The same TestObject works fine with

JavaScript??? :scream:
Back to you, @Russ_Thomas :smile:

Sorry, Marko, I don’t know. But if the regular works, use that. Maybe Russ will know more about the JS execution.