kris82pl
kris82pl

Reputation: 1109

Wait until elementToBeClickable is not the solution for other element would receive the click exception

Yesterday I ask question how to deal with: "Element is not clickable at point - other element would receive the click" exception in Selenium WebDriver.

I receive several answers with this solution:

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id(...));

Yes, it has sense but in practice it doesn't work. Below is piece of my code:

                JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("arguments[0].scrollIntoView();", categoryItem);
            Thread.sleep(1000);
            new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(categoryItem));
            categoryItem.click();
            List<WebElement> selects = driver.findElements(By.tagName("select"));
            Select ticketsSelect = new Select(selects.get(3));
            ticketsSelect.selectByValue("2");

            By addToBasket = By.xpath("//div[contains(text(),'Add to Basket')]");
            Thread.sleep(1000);
            new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(addToBasket));
            driver.findElement(addToBasket).click();

I had to put 1 second sleep before each wait until element to be clickable because without this it still throw exception that other element would receive the click. My question is why WebDriver clicks this element if element is not clickable ?

Upvotes: 2

Views: 2039

Answers (1)

Igor Milla
Igor Milla

Reputation: 2786

ElementToBeClickable – An expectation for checking an element is visible and enabled such that you can click it.

But it seems that it doesn't imply that this element is not "hidden" under some other element, even if it's a transparent part of another tag. In my experience, this exception is mostly occur when you are trying to interact with a page, which currently loads, and you have typical loading div overlapping the whole page with loading icon, or in other cases when you have an open modal, which also often cover page with overlays transparent overlay, to prevent user from interacting with a page.

In this answer you can see that you basically have two options:

  1. You can send a click event via JavaScript call. It will always work, but it's not something you want to do. If you want to test your page, you should always trigger real click events.
  2. Wait. There is not much you can do. Something you just need to wait till your page fully loads. In a way maybe this will show you the slow parts of your application, which you can improve in a future

Upvotes: 2

Related Questions