Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpectedConditions.invisibilityOfElementLocated doesn't work

I have this code

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id(".....")));
webDriver.findElement(By.xpath(".......")).click();

Sometimes I get exception:

org.openqa.selenium.WebDriverException: unknown error: Element <a href="#" onclick="showRelatedPerson();return false;" class="button-alt button-icon">...</a> is not clickable at point (1233, 710). Other element would receive the click: <div id="jquery-msg-bg" style="width: 100%; height: 100%; top: 0px; left: 0px;"></div>

This is the element that I am trying to avoid by wait that I put. I am waiting until it becomes invisible, but sometimes even if it becomes invisible it still can receive the click and it is blocking the proper element to be clicked.

like image 409
lijep dam Avatar asked Jul 23 '26 05:07

lijep dam


2 Answers

The problem was that once test reaches first line, the element that I wait to be invisible was not visible yet, but as test completes this line element becomes visible. So the solution was to add one more line at the beginning:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("jquery-msg-bg")));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("jquery-msg-bg")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("declarationBusinessParticularsActivity.isMain")));
like image 154
lijep dam Avatar answered Jul 25 '26 10:07

lijep dam


I've been using Selenium for 3 years. I was happy to try new version 4, yet it dissapoints me. I do not trust in ExpectedConditions as they do not work or doesn't provide the expected results. I do use them, but I often implement my own waits.

Try using this (I used this simple solution in many projects and it just works).

WebElement x = driver.findElement(locator);
while(x.isDisplayed())
    Thread.sleep(100);
like image 42
Fragsman Avatar answered Jul 25 '26 11:07

Fragsman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!