2

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?

2

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.

| improve this answer | |
1

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
| improve this answer | |
  • 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 Sep 30 '16 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. – Niels van Reijmersdal Oct 1 '16 at 11:25
1

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()) {
        onlineRegistrationPopupClose.click();
        wait.until(ExpectedConditions.invisibilityOf(onlineRegistrationPopupClose));
    }
}
| improve this answer | |
0

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

| improve this answer | |
0

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.

| improve this answer | |
0

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)
            {
                continue;
            }
            else break;

        }

    }
| improve this answer | |
-1

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()
        {


            Thread.Sleep(2000);
            if (<check your div panel is visible or not>)
            {

                    Thread.Sleep(2000);
                    //again cal the same method
                    CheckDivPane();


            }

            else
            {
                Perform the action

            }
        }
| improve this answer | |
  • Yes, currently I'm using Sleep() but I prefer dynamic waiting. Thanks anyway. – FDM Oct 3 '16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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