Reputation: 1109
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
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:
Upvotes: 2