# Need Help Troubleshooting Button Click Error

**URL:** <https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591>\
**Category:** Miscellaneous\
**Created:** [July 4, 2024, 8:46am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591 "2024-07-04T08:46:09Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 4, 2024, 8:46am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/1 "2024-07-04T08:46:09Z")

</div>

Hi All,

Can someone help me troubleshoot an error I encounter when clicking a button?

**Error:**  
**`Caused by: org.openqa.selenium.ElementClickInterceptedException: element click intercepted`**

If I use ‘Enhanced Click’ instead of ‘Click’, the problem is fixed. However, the execution time increases significantly. How can I resolve this issue without compromising performance?

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [July 4, 2024, 8:46am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/2 "2024-07-04T08:46:09Z")

</div>

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 4, 2024, 9:44am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/3 "2024-07-04T09:44:39Z")

</div>

> [@mch](#):
>
> **`Caused by: org.openqa.selenium.ElementClickInterceptedException: element click intercepted`**

Please note that I also tried adding ‘wait for element to be clickable’ before clicking the button, but the same error occurred.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 4, 2024, 4:27pm UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/4 "2024-07-04T16:27:12Z")

</div>

I had a similar issue when I tried to click on a button using `WebUI.click(...)`. My HTML was like:

```auto
<div>
     <input ...
     <button ...
<div>

```

I was able to get the button to click using Javascript.

> **Maybe like:**
>
> ```auto
> import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor
> import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebHelper
> 
> /**
> * Perform a click on Test Object
> * @param element = our Test Object
> * @param timeout (optional)
> */
> @Keyword
> public static clickButtonJS(TestObject to, int timeout = 10) {
> try {
> WebElement element = WebUI.findWebElement(to, timeout)
> WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))
> } catch (Exception) {
> WebUI.comment("Could not click on Test Object")
> }
> }
> 
> /**
> * Perform a click on Web Element
> * @param element = our Web Element
> */
> @Keyword
> public static clickElementJS(WebElement element) {
> try {
> WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))
> } catch (Exception) {
> WebUI.comment("Could not click on Web Element")
> }
> }
> 
> ```

Edit: you can use `WebHelper` or `WebUI` for “findWebElement”. I just changed it to the latter.

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 4, 2024, 8:48pm UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/5 "2024-07-04T20:48:03Z")

</div>

Hi,

Why should we proceed with these additional JavaScript steps when we already have the capability to use Katalon with the recorder?

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [July 4, 2024, 8:53pm UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/6 "2024-07-04T20:53:41Z")

</div>

> [@mch](#):
>
> Caused by: org.openqa.selenium.ElementClickInterceptedException: element click intercepted

Edit: I am assuming you are using the **web recorder** of Katalon Studio, and not their other product, Katalon Recorder. If you are using Katalon Recorder, you would have to put the method into a function, which I will let you search this forum as others have done similar.

I have the javascript as a Keyword since I need to use it for **all the buttons** that are in the specific pattern I stated above, otherwise, my test case **click** fails. Basically, it was due to the HTML of the page I was working on. You can put the Keyword into your code, in-line if you want to try it. If you want to get past your Exception, I give you what I had to do.

Maybe someone else has a “better” option.

Edit2: you can create a method within your Test Case **above** your code and **below** the **import** statements and call it within your test case. You can copy and paste the method into the Script tab, and then “find and replace” your `WebUI.click` to `clickButtonJS` and see if it works. Back up your project beforehand!

```auto
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

	public clickButtonJS(TestObject to, int timeout = 10) {
		try {
			WebElement element = WebUI.findWebElement(to, timeout)
			WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))
		} catch (Exception) {
			WebUI.comment("Could not click on Test Object")
		}
    }

//blah blah blah

clickButtonJS(findTestObject('myPage/button_Login'), 10)
// or
clickButtonJS(findTestObject('myPage/button_Login'))

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 5, 2024, 1:02am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/7 "2024-07-05T01:02:32Z")

</div>

> [@mch](#):
>
> Why should we proceed with these additional JavaScript steps

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:

```auto
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:

1. try to click the HTML element by the ordinary WebElement.click() method. If failed, will fall down to the following step.
2. 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.
3. 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.

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 5, 2024, 7:16am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/8 "2024-07-05T07:16:33Z")

</div>

Hi @kazurayam and @grylion54 ,

Thank you both for your messages and assistance.

@kazurayam , do you mean to extract step 2 from the code? I am a bit confused about how I can integrate the Enhanced Click feature with the code that @grylion54 suggested. Could you please provide further guidance on this?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 5, 2024, 7:17am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/9 "2024-07-05T07:17:52Z")

</div>

All I am saying is, you don’t need the Enhanced Click at all.

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 5, 2024, 8:29am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/10 "2024-07-05T08:29:40Z")

</div>

Yes I am using the Web Recorder.

So, the solution for Web Recorder is to create a new keyword named, for example, `clickJS` and insert the code you mentioned above? Can you please explain more? Sorry for the questions, I am a beginner in Katalon…

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 5, 2024, 8:34am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/11 "2024-07-05T08:34:35Z")

</div>

I don’t understand your question.

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 5, 2024, 9:00am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/12 "2024-07-05T09:00:30Z")

</div>

Can you please explain the steps I must follow to resolve the issue with the web recorder? I am getting confused.

---

<div class="post-metadata">

**Author:** ![mch](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mch/32/23869_2.png) [@mch](https://forum.katalon.com/u/mch)\
**Post date:** [July 5, 2024, 9:37am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/13 "2024-07-05T09:37:46Z")

</div>

I have created the custom keyword ‘clickKeywordJS’ and now I want to replace it with the default click keyword so that I don’t have to manually change it every time. Is it possible?  
 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/5/e/5eeac33abe7f6b6670ee8ec1a63627c7a4e06eac.png)

So to give me you more details, if I will use the web recorder then automatically will inherit the ‘clickKeywordJS’ instead of click.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 5, 2024, 12:55pm UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/14 "2024-07-05T12:55:44Z")

</div>

> [@mch](#):
>
> now I want to replace it with the default click keyword so that I don’t have to manually change it every time. Is it possible?

Yes, it is possible.

You want to use Groovy’s feature called “ExpandoMetaClass”. Read the doc:

[https://www.groovy-lang.org/metaprogramming.html#metaprogramming\_emc](https://www.groovy-lang.org/metaprogramming.html#metaprogramming_emc)

I have applied this technique to my Katalon projects several times. See the following post for example:

> [@How to Highlight Test object in each and every step](http://forum.katalon.com/t/how-to-highlight-test-object-in-each-and-every-step/17408/6):
>
> I have got a success. Have a look at this demo project and try it. You can see the demo movie here: [https://kazurayam.github.io/HighlightingElementByTestObjectInEachAndEveryStep/](https://kazurayam.github.io/HighlightingElementByTestObjectInEachAndEveryStep/) To @nikhil.nareddy Thank you for your hint.

Be informed, in order to utilize the “Metaprogramming” technique, you need to read the source code of katalon studio WebUI API. I described how to get the source codes in [the previous post](http://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/7)

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [July 18, 2024, 10:16am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/16 "2024-07-18T10:16:36Z")

</div>

Hi there @mch, 👋

Just checking to see if you were able to find a solution to your question based on the other comments in this thread or not.

If yes, then please don’t forget to mark helpful replies **as a solution ✅** so that others who may be asking similar questions / running into similar problems can find the solution as well!

Thanks 🕶

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [July 27, 2024, 1:00am UTC](https://forum.katalon.com/t/need-help-troubleshooting-button-click-error/136591/17 "2024-07-27T01:00:40Z")

</div>

Closed on July 27, 2024, 1:00am UTC

This topic was automatically closed after 17 hours. New replies are no longer allowed.
