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));
            }
        }
2
  • 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. Commented Dec 9, 2019 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
    Commented Dec 9, 2019 at 10:01

2 Answers 2

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
1
  • I want to wait for the spinner. If the spinner disappears then I want to continue with the next step. Can you please send me an example code that works?
    – Majkl
    Commented Apr 6, 2022 at 8:57
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 } }

1
  • I really want to wait for the spinner. If the spinner disappears then I want to continue with the next step. Can you please send me an example code that works? I have not waitForNotVisible option there.
    – Majkl
    Commented Apr 6, 2022 at 8:58

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.