I would try to answer to this question.
Let me translate the question: The Enhanced Click works fine, but it takes significantly long time. Why?
In the folder where you installed Katalon Studio, you would find the source code of com.kms.katalon.core.webui.keyword.builtin.EnhancedClickKeyword, which is the implementation of the “Enhanced Click” keyword.
See <Katalon installatio folder>/Contents/Eclipse/configuration/resources/source folder, where you will find several jar files. Please find a jar file com.kms.katlaon.core.webui/com.kms.katalon.core.webui-sources.jar. Unzip the jar file. You will find a Groovy source code com/kms/katalon/core/webui/keyword/builtin/EnhancedClickKeyword.groovy.
Here I quote the whole code:
package com.kms.katalon.core.webui.keyword.builtin
import java.text.MessageFormat
import org.openqa.selenium.JavascriptExecutor
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.interactions.Actions
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
import com.kms.katalon.core.annotation.internal.Action
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.exception.StepFailedException
import com.kms.katalon.core.helper.KeywordHelper
import com.kms.katalon.core.keyword.internal.SupportLevel
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.trymonad.Try
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.constants.StringConstants
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword
import com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain
import groovy.transform.CompileStatic
@Action(value = "enhancedClick")
class EnhancedClickKeyword extends WebUIAbstractKeyword {
@CompileStatic
@Override
public SupportLevel getSupportLevel(Object ...params) {
return super.getSupportLevel(params)
}
@CompileStatic
@Override
public Object execute(Object ...params) {
TestObject to = getTestObject(params[0])
FailureHandling flowControl = (FailureHandling)(params.length > 1 && params[1] instanceof FailureHandling ? params[1] : RunConfiguration.getDefaultFailureHandling())
click(to,flowControl)
}
private void scrollToElement(WebDriver webDriver, WebElement webElement) {
try {
Actions builder = new Actions(webDriver);
builder.moveToElement(webElement);
builder.build().perform();
} catch(Exception e) {
logger.logError(e.getMessage());
}
try {
((JavascriptExecutor) webDriver).executeScript("arguments[0].scrollIntoView(true);", webElement);
} catch(Exception e) {
logger.logError(e.getMessage());
}
}
@CompileStatic
public void click(TestObject to, FailureHandling flowControl) throws StepFailedException {
WebUIKeywordMain.runKeyword({
boolean isSwitchIntoFrame = false
try {
WebUiCommonHelper.checkTestObjectParameter(to)
isSwitchIntoFrame = WebUiCommonHelper.switchToParentFrame(to)
WebElement webElement = WebUIAbstractKeyword.findWebElement(to)
WebDriver webDriver = DriverFactory.getWebDriver();
int timeout = KeywordHelper.checkTimeout(RunConfiguration.getTimeOut())
logger.logDebug(MessageFormat.format(StringConstants.KW_LOG_INFO_CLICKING_ON_OBJ, to.getObjectId()))
Try.ofFailable({
logger.logDebug("Trying Selenium click !");
webElement.click();
return Boolean.TRUE;
}).orElseTry({
logger.logDebug("Trying to scroll to the element, wait for it to be clickable and use Selenium click !");
scrollToElement(webDriver, webElement);
WebDriverWait wait = new WebDriverWait(webDriver, timeout);
webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
webElement.click();
return Boolean.TRUE;
}).orElseTry({
logger.logDebug("Trying Javascript click !");
JavascriptExecutor executor = (JavascriptExecutor) webDriver;
executor.executeScript("arguments[0].click();", webElement);
return Boolean.TRUE;
}).onSuccess({
logger.logPassed(MessageFormat.format(StringConstants.KW_LOG_PASSED_OBJ_CLICKED, to.getObjectId()))
}).get();
} finally {
if (isSwitchIntoFrame) {
WebUiCommonHelper.switchToDefaultContent()
}
}
}, flowControl, true, (to != null) ? MessageFormat.format(StringConstants.KW_MSG_CANNOT_CLICK_ON_OBJ_X, to.getObjectId())
: StringConstants.KW_MSG_CANNOT_CLICK_ON_OBJ)
}
}
Please read the code to find how the click method is implemented.
The click method sequentially tries the following 3 steps:
- try to click the HTML element by the ordinary WebElement.click() method. If failed, will fall down to the following step.
- try to scroll to the element and click the element by WebElement.click() with Wait. The Wait will expire after 30 seconds as default. If failed, will fall down to the following step.
- try to click the element by executing a javascript
arguments[0].click()
The implementation is as such that the Enhanced Click is likely to take 30 seconds or longer at the step2.
@grylion54 suggested to go to the step3 immediately skipping the step2. It will run quickly.
The Enhanced Click keyword involves a JavaScript call, which is not really “additional”, rather is essencial.