So, in the AUT there's a <div> loading screen covering the entire page, which then fades out and gets replaced in the DOM by the <body>.

I'm using ExpectedConditions for visibility and clickable, but while these elements are already being displayed, the loading screen is still fading out, so of course I'm getting:

System.InvalidOperationException: unknown error: 
Element is not clickable at point (115, 327). 
Other element would receive the click: <div class="pg-loading-center-middle">...</div>

Can I dynamically wait in another way to account for the fade delay?

7 Answers 7


Instead of waiting for your element, try to put wait for the invisibility of previous element. Like try the below code:

WebDriverWait wait = new WebDriverWait(driver, 100);

    boolean waitUntil = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//Div")));

Might be it will help you out.


Can't you just wait for the loading element to be not visible with the .isDisplayed() function?

  • Wait for body elements to be displayed
  • Wait for pg-loading-center-middle div to be not displayed
  • Click element
  • That is exactly what I do. The problem is that javascript (1) adds the body to the DOM but also (2) fades out the div (even though it's no longer present, you still see it for another second). For Selenium, the body is visible (because the div has become transparant, but it's still there on top).
    – FDM
    Commented Sep 30, 2016 at 15:31
  • Hmm. A fade only changes the opacity, so possibly it is still there when Selenium thinks it is gone, maybe you need to wait for a couple of (milli)seconds for the code to remove the loading div. In the past I have asked the developers to add an isReady() javascript function to the page which I would execute with the JavaScript executer to check if any JavaScript was running. Commented Oct 1, 2016 at 11:25

I use the Page-Object-Model, so I have referenced elements (by default at least), and then I have a conditional "popup" element that displays some information, with a covering div in the background. So, similar effective situation to the OP.

The solution I use related to your issue is to check for the relevant popup element. If it exists, perform the close, then execute the wait (using invisibilityOf()) on the same relevant element (which is part of the popup), regardless of the next operation. This then ensures the next operation does not get blocked. It works in my case because the visibility of the element inherits the visibility of the popup structure (W3C).

Here are the relevant parts for this setup:

@FindBy(how = How.XPATH, using = "//*[@id='content_panel']/div[2]/div[1]/span")
private WebElement onlineRegistrationPopupClose;

public void CloseOnlineRegistrationPopup() throws Exception {       
    WebDriverWait wait = new WebDriverWait(driver, 5);

    // try and close this, then wait a moment for the element to be invisible       
    if (onlineRegistrationPopupClose.isDisplayed()) {

I am assuming the overlay changes the colours of the elements on the screen so how about looking for it using its colour?

For example is you use something like;

rgb = find_element_by_class_name("pg-loading-center-middle").value_of_css_property('background-color')

you will be returned a string along the lines of;

rgb(221, 81, 76)

Using a tool like Firefox's eyedropper you should be able to put in a wait condition until the values match up


but while these elements are already being displayed, the loading screen is still fading out,

This is a good example where using visual web testing (via screenshots) make things easier. You can combine Selenium with Sikuli or Kantu, and then wait for the image of the button/text to change.


I Tried the following function, but sometimes this is failing with element not clickable error.

public void waitToClosePopupWindow(By LocatorToFadeOut, By LocatorToBeInvisible) throws Throwable  
        int size = 0;
        for(int i=0; i<50;i++)
            String className = driver.findElement(LocatorToFadeOut).getAttribute("class");
// This code is to wait till modal-open is disappeared from DOM
// <body class="sidebar-xs ng-scope pace-done modal-open" ng-app="apps" ng-controller="layoutController as layout">
            size = driver.findElements(LocatorToBeInvisible).size();
// this code is to wait untial a div is disappeared from DOM once the overlay windown has been closed
            if(className.contains("modal-open") && size>0)
            else break;



I really dont no whether this helps you or not ,Any how try to get some idea or try to implement something with he same logic.

 public void CheckDivPane()

            if (<check your div panel is visible or not>)

                    //again cal the same method


                Perform the action

  • Yes, currently I'm using Sleep() but I prefer dynamic waiting. Thanks anyway.
    – FDM
    Commented Oct 3, 2016 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.