The element is not clickable

@Curtis_BRODERICK

Exactly as Russ and I have said, if it’s something that you want to use across multiple scripts (which you almost certainly will if it worked for you already), you will want to encapsulate this into a method. Russ has linked you a demo on generally how to create/work with Custom Keywords, but I can also give you a brief demo and some code to get you started:

1.) In your Tests Explorer, right click on Keywords, then click on New > Keyword
image

2.) You’ll be prompted with a dialog. For now, just call the Package “util” and the Class Name “Util” (this follows Java convention):
image
Feel free to reorganize/rename things later of course.

3.) Since you said you are using the Object Repository, I will assume that you will be passing TestObjects to the utility method. If that’s the case, go ahead and copy over all of the auto-generated code in your Util class with the following (Updated this to match the solution from below that seems to work better):

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);
	}
}

4.) You can then call this method from ANY Test Case that you want just by importing the Util class, and calling the method:

import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject

// This is the import statement for the "Util" Custom Keyword we've created:
import util.Util

TestObject myTestObject = ObjectRepository.findTestObject("path/to/my/object");
Util.jsClick(myTestObject);

If you choose not to wrap this up into a method, you will be forced to type out this code yourself anytime you want to use JS to click something, which obviously isn’t great.

Hope this helps!

2 Likes