JustToKnow
JustToKnow

Reputation: 823

is not clickable at point (44, 230) - Selenium strange behaviour while trying to click

This is the error:

Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element ... is not clickable at point (44, 230). Other element would receive the click: ...

I got these 2 buttons (CATALOG and PRODUCTS):

enter image description here

CATALOG has this:

<a href="#" onclick="return false;" class="_active"><span>Catalog</span></a>

XPATH:

//*[@id="menu-catalog-catalog"]/a

PRODUCTS button has this:

<a href="https://testing.testing/backend/catalog/product/index/key/c3b3205a4808f24f54ac05c10ee0035f5497b72e83f5a6617efe18bbdb9353be/" class=""><span>Products</span></a>

and this XPATH:

//*[@id="menu-catalog-catalog"]/div/ul/li/div/ul/li[1]/a

I did this in both cases:

driver.findElement(By.xpath("//*[@id=\"menu-catalog-catalog\"]/a")).click();


driver.findElement(By.xpath("//*[@id=\"menu-catalog-catalog\"]/div/ul/li/div/ul/li[1]/a")).click();

The problem is that sometimes it clicks on the buttons and sometimes don't so i dont know what's going on.


A new button:

<button class="action-submit" type="button" data-bind="click: apply.bind($data, false)">
        <span data-bind="i18n: 'Search'">Search</span>
    </button>

It's XPATH:

//*[@id="container"]/div/div[2]/div[1]/div[5]/button
    

Take a look at this:

enter image description here

The SEARCH ICON has this:

<button class="action-submit" type="button" data-bind="click: apply.bind($data, false)">
        <span data-bind="i18n: 'Search'">Search</span>
    </button>

XPATH:

//*[@id="container"]/div/div[2]/div[1]/div[5]/button

And then, i click on the grid and it has this:

<td data-bind="css: getFieldClass($row()), click: getFieldHandler($row()), template: getBody()">
<div class="data-grid-cell-content white-space-preserved" data-bind="html: $col.getLabel($row())">HISENSE 32"</div>
</td>

And XPATH:

//*[@id="container"]/div/div[4]/table/tbody/tr/td[4]

I did this:

driver.findElement(By.xpath("//*[@id=\"container\"]/div/div[2]/div[1]/div[5]/button")).click();

driver.findElement(By.xpath("//*[@id=\"container\"]/div/div[4]/table/tbody/tr/td[7]")).click();

Upvotes: 0

Views: 56

Answers (2)

Prophet
Prophet

Reputation: 33361

In case even after using WebDriverWait ExpectedConditions.elementToBeClickable you getting Element ... is not clickable at point error I'd suggest clicking that element with JavaScript.
Normally this approach is not recommended, but if no better way this powerful tool can be used.
Trying to improve Kunduk's answer.
So, please try this:

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));   
JavascriptExecutor executor = (JavascriptExecutor)driver;
WebElement elementCat = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[text()='Catalog']]")));  
executor.executeScript("arguments[0].click();", elementCat);
WebElement elementProd = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[text()='Products']]")));
executor.executeScript("arguments[0].click();", elementProd);

Upvotes: 1

KunduK
KunduK

Reputation: 33384

Use webdriverwait() and wait for element to be clickable.

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10)); 
WebElement elementCat = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[text()='Catalog']]")));
elementCat.click();
WebElement elementProd = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[text()='Products']]")));
elementProd.click();

If you are still getting similar error you might need to use action class or inject javascripts executor.

Upvotes: 1

Related Questions