29

I am trying to make some tests using selenium based Katalon Studio. In one of my tests I have to write inside a textarea. The problem is that I get the following error:

...Element MyElement is not clickable at point (x, y)... Other element would receive the click...

In fact my element is place inside some other diva that might hide it but how can I make the click event hit my textarea?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
nix86
  • 2,837
  • 11
  • 36
  • 69
  • You should get some knowledge about implicit and explicit waits in WebDriver. It will helps you how to deal with visible\not visible elements. – kyxap Jun 23 '17 at 20:04

5 Answers5

54

Element ... is not clickable at point (x, y). Other element would receive the click" can be caused for different factors. You can address them by either of the following procedures:

  1. Element not getting clicked due to JavaScript or AJAX calls present

Try to use Actions Class:

WebElement element = driver.findElement(By.id("id1"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
  1. Element not getting clicked as it is not within Viewport

Try to use JavascriptExecutor to bring the element within Viewport:

JavascriptExecutor jse1 = (JavascriptExecutor)driver;
jse1.executeScript("scroll(250, 0)"); // if the element is on top.
jse1.executeScript("scroll(0, 250)"); // if the element is at bottom.

Or

WebElement myelement = driver.findElement(By.id("id1"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement); 
  1. The page is getting refreshed before the element gets clickable.

In this case induce some wait.

  1. Element is present in the DOM but not clickable.

In this case add some ExplicitWait for the element to be clickable.

WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("id1")));
  1. Element is present but having temporary Overlay.

In this case induce ExplicitWait with ExpectedConditions set to invisibilityOfElementLocated for the Overlay to be invisible.

WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
  1. Element is present but having permanent Overlay.

Use JavascriptExecutor to send the click directly on the element.

WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • But I'm not using javascript. I use katalon that uses java. – nix86 Jun 23 '17 at 15:11
  • 1
    I have partially solved the problem by putting a Thread.sleep before the click. – nix86 Jun 23 '17 at 15:22
  • 3
    @nix86 `Thread.sleep()` degrades your Test performance. So avoid `Thread.sleep()`. `ImplicitlyWait` may be discontinued anytime. So try out `ExplicitWait` as I mentioned in my Answer. – undetected Selenium Jun 23 '17 at 15:28
  • But how is the driver variable defined? – nix86 Jun 26 '17 at 07:23
  • @nix86 Can you consider showing us your work please along with the relevant HTML DOM so that we can guide you properly? Thanks – undetected Selenium Jun 26 '17 at 07:40
  • For other people, wondering how to get get xpath of the **temporary** Overlay in the 5th option: 1. set breakpoint on DOM modification in Chrome (https://developers.google.com/web/tools/chrome-devtools/javascript/breakpoints#dom) and 2. right-click on the overlay element in the tree of Elements and choose "Copy -> Copy XPath" – DimanNe Nov 24 '19 at 08:26
3

I assume, you've checked already that there is no any other component overlapping here (transparent advertisement-iframes or some other component of the DOM => seen quite often such things in input/textfield elements) and, when manually (slowly) stepping your code, it's working smoothly, then ajax calls might cause this behaviour.

To avoid thread.sleep, try sticking with EventFiringWebDriver and register a handle to it. (Depending on your application's techstack you may work it for Angular, JQuery or wicket in the handler, thus requiring different implementations) (Btw: This approach also got me rid of "StaleElementException" stuff lots of times)

see: org.openqa.selenium.support.events.EventFiringWebDriver org.openqa.selenium.support.events.WebDriverEventListener

driveme = new ChromeDriver();
driver = new EventFiringWebDriver(driveme);
ActivityCapture handle=new ActivityCapture();
driver.register(handle);

=> ActivityCapture implements WebDriverEventListener e.g. javascriptExecutor to deal with Ajax calls in a wicket/dojo techstack

    @Override
public void beforeClickOn(WebElement arg0, WebDriver event1) {
    try {
        System.out.println("After click "+arg0.toString());
        //System.out.println("Start afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis());
        JavascriptExecutor executor = (JavascriptExecutor) event1;
        StringBuffer javaScript = new StringBuffer();
        javaScript.append("for (var c in Wicket.channelManager.channels) {");
        javaScript.append(" if (Wicket.channelManager.channels[c].busy) {");
        javaScript.append(" return true;");
        javaScript.append(" }");
        ;
        ;
        ;
        javaScript.append("}");
        javaScript.append("return false;");
        //Boolean result = (Boolean) executor.executeScript(javaScript.toString());
        WebDriverWait wait = new WebDriverWait(event1, 20);
        wait.until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driver) {
                return !(Boolean) executor.executeScript(javaScript.toString());
            }
        });
        //System.out.println("End afterClickOn - timestamp: System.currentTimeMillis(): " + System.currentTimeMillis());
    } catch (Exception ex) {
        //ex.printStackTrace();
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
ulrayk
  • 31
  • 1
2

As @DebanjanB said, your button (or another element) could be temporarily covered by another element, but you can wait and click it even if you don't know which element is covering the button.
To do this, you can define your own ExpectedCondition with the click action:

public class SuccessfulClick implements ExpectedCondition<Boolean> {
    private WebElement element;

    public SuccessfulClick(WebElement element) { //WebElement element
        this.element = element;
    }

    @Override
    public Boolean apply(WebDriver driver) {
        try {
            element.click();
            return true;
        } catch (ElementClickInterceptedException | StaleElementReferenceException | NoSuchElementException e) {
            return false;
        }
    }
}

and then use this:

WebDriverWait wait10 = new WebDriverWait(driver, 10);
wait10.until(elementToBeClickable(btn));
wait10.until(new SuccessfulClick(btn));
Adam Silenko
  • 3,025
  • 1
  • 14
  • 30
-1

Try Thread.Sleep()

Implicit - Thread.Sleep()

So this isn’t actually a feature of Selenium WebDriver, it’s a common feature in most programming languages though. But none of that matter.

Thread.Sleep() does exactly what you think it does, it’s sleeps the thread. So when your program runs, in the majority of your cases that program will be some automated checks, they are running on a thread. So when we call Thread.Sleep we are instructing our program to do absolutely nothing for a period of time, just sleep. It doesn’t matter what our application under test is up to, we don’t care, our checks are having a nap time!

Depressingly though, it’s fairly common to see a few instances of Thread.Sleep() in Selenium WebDriver GUI check frameworks. What tends to happen is a script will be failing or failing sporadically, and someone runs it locally and realises there is a race, that sometimes WedDriver is losing. It could be that an application sometimes takes longer to load, perhaps when it has more data, so to fix it they tell WebDriver to take a nap, to ensure that the application is loaded before the check continues.

Thread.sleep(5000);

The value provided is in milliseconds, so this code would sleep the check for 5 seconds.

Pradnya Bolli
  • 1,915
  • 1
  • 19
  • 37
-2

I was having this problem, because I had clicked into a menu option that expanded, changing the size of the scrollable area, and the position of the other items. So I just had my program click back on the next level up of the menu, then forward again, to the level of the menu I was trying to access. It put the menu back to the original positioning so this "click intercepted" error would no longer happen.

The error didn't happen every time I clicked an expandable menu, only when the expandable menu option was already all the way at the bottom of its scrollable area.