0

I'm using the code below, waiting for "Loading" spinner to disappear. But I noticed that next test step does not wait until the spinner to disappear.

Example:

  1. click on button_1 (after click, spinner is displayed)
  2. waiting until spinner to disappear
  3. click on button_2

So, I noticed error because button_2 is unclickable until Loading spinner is displayed.

How to deal with this situation, please?

protected By LoadingSpinnerBy = By.XPath("//*[@id='loadingGrid']");

/// <summary>
        /// Method to wait for page load to complete and loading spinner to be invisible
        /// </summary>
        public void WaitForLoadingSpinnerToGo()
        {
            if (_driver.FindElements(LoadingSpinnerBy).Count > 0)
            {
                _wait.Until(ExpectedConditions.InvisibilityOfElementLocated(LoadingSpinnerBy));
            }
        }
  • What happens if you want for the button_2 to be clickable? If it's unclickable due the spinner or anything else quite doesn't matter. – João Farias Dec 9 '19 at 9:55
  • Hi are you validating spinner to be visible first ?, sometimes spinner takes time to be displayed and by that time your invisibility condition will be true. So you will have spinner being displayed in the next step – PDHide Dec 9 '19 at 10:01
1

Hi are you validating spinner to be visible first ?,

_wait.Until(ExpectedConditions.visibilityOfElementLocated(LoadingSpinnerBy));

sometimes spinner takes time to be displayed, and by that time your invisibility condition will be true. So you will have spinner being displayed in the next step

The correct approach would be to:

  1. validate that spinner is displayed
  2. validate spinner gets disappeared
  3. validate button 2 is clickable
0

If your goal is just to click button_2, you can use javascript click which will click the element even it is not displayed but it's present.

DriverUtils.getDriver().executeScript("arguments[0].click();", elem);

But it you really want to wait for the spinner first you can have:

public void WaitForLoadingSpinnerToGo() { try { _driver.FindElement(LoadingSpinnerBy).waitForNotVisible(60000); } catch(Exception e) { //Todo when spinner is still displayed after 1 minute } }

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.