The element is not clickable

Brandon, thank you for this util sample. This static approach I am also going to use it for my projects tomorrow :wink:

Wow! @Brandon_Hein I see that you perceived clearly when I said “never programmed in java”. Thanks for the very clear instructions. Thanks @Russ_Thomas for clarifying as well. Before trying Brendon’s keyword solution, I used the ‘self contained’ solution (I hate saying the word method here as it really confuses things) which did successfully get to that button that was hidden under some other object(s). Commented out that and then tried with my new keyword in my util package.

Unfortunately, Katalon doesn’t seem to find the method executeJavaScript() as it spits this back to me.
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript()
and then points to line 13 of the Util.groovy: WebUI.executeJavaScript(“arguments[0].click();”, element);

@Curtis_BRODERICK

Yea, the WebUI API can be troublesome at times (or I’m just using it incorrectly). Since the approach in my original comment seemed to work for you, we can just use that. It’s a bit more verbose, but not too bad. Go ahead and replace your Util class with this:

package util

import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory

public class Util {

	public static void jsClick(final TestObject testObject) {
		WebElement element = WebUiCommonHelper.findWebElement(testObject, 30);
		WebDriver driver = DriverFactory.getWebDriver();
		JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
		jsExecutor.executeScript("arguments[0].click();", element);
	}
}

I ran this on my side as well to be sure, should work fine :slight_smile: I’ve updated the demo I gave above to match this.

Side note: A “method” in Java is analogous to a “function” in C/JavaScript/etc. It’s just a set of code you can call to do some chunk of work for you.

2 Likes

YES Excellent. Just about to leave the office and bing, it works. BIG thanks Brendon and Russ.
Curtis

Glad to help :metal:

Hello, I’m a beginner, thank you all for your contributions. I’ve also the same problem. I’ts a greatful tips :slight_smile:

Hi @Brandon_Hein,

I have tried your solution to click in a toggle button, but the script stops in those steps (it doesn’t fail) and I see that the button is not clicked.

Any suggestion?

Thanks,
Ruben B

You should make sure the buttton is present and is clickable before you actually click it.

There are a few Katalon build-in keywords to wait for element. For example, you can do:

TestObject myTestObject = ObjectRepository.findTestObject("Page_Acronyms and Terms  Insider/span_My Acronyms");
// wait for the element to appear
WebUI.verifyElementPresent(myTestObject, 10)
// then click it
Util.jsClick(myTestObject)

If you prefer Selenium WebDriver native approach, the following post may be informative:

Hi @kazurayam,

Thanks for the info. I found the below js that worked

import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import org.openqa.selenium.interactions.Actions as Actions
import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.testobject.TestObject

@Keyword
def clickUsingJS(TestObject to, int timeout) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript(‘arguments[0].click()’, element)
}

in the script:

CustomKeywords.‘ClickJS.clickUsingJS’(findTestObject(‘Page_Acronyms and Terms Insider/span_My Acronyms’), 30)

Thanks,
Ruben B

Thanks a lot :grinning: