Having problems with keyword WebUI.enhancedClick()

I am getting an error when I use WebUI.enhancedClick(), but this only happens in Firefox with a specific web element with the following xpath:

(//*[contains(@class, 'svg-overlay')]/child::*/*[contains(@class, 'active')]/parent::*)[${index}]

Index is passed as a parameter because there’s several elements and the script chooses one randomly. I get the following error (can share the full log if needed):

Caused by: org.openqa.selenium.JavascriptException: TypeError: arguments[0].click is not a function

I can’t change the code of the enhancedClick() keyword, but the same happens if I use the following block of code:

WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript("arguments[0].click()",element)

As you can see, click() is being used correctly there, and I am sure it’s also correct in the enhancedClick() keyword (it works in all other cases), so I am not sure why I get that error.

Did anyone face the same issue with some web element before?

No, actually, what I see is a set of code which may or may not work depending on many factors. Just because it looks right, doesn’t mean it’s correct.

I can only guess at what your underlying problem is – most likely your index is out of range.

The error for out of range is usually different. In any case I checked by printing the index that was chosen and then going manually to the page search for the element, and it exists, so it’s not that.

What I mean is if you use click that won’t work. You need to use click() and I am using it correctly and it still doesn’t work. The error message says that click is not a function, which is weird because I used click().

Still can’t understand why it only happens in Firefox.

That’s how the error message is supposed to look. that’s NOT your problem.

Aside: To prove the point, open DevTools, and type this into the console:
“Joana”.click()

image

Unless you show me more of your code and HTML for the elements, I can’t really help you.

I think I figured it out! Basically this was a HTML element with a nested element inside. For firefox, apparently, it needs the child element to be able to click. Now it’s working.