Issue with clicking on button using JavaScript


#1

Hi
I have created the following keyword:
@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 WebUI.click() 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?


#2

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.


#3

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:


Chrome headless failed
#4

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 WebUI.click().


#5

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

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