I am automating a web application with selenium c#.
After login I have to handle a spinner which appears in the home page.
I have given explicit wait
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(LocatorSelect(locator, locatorvalue)));
And the result is getting passed and script wait for the element to be visible.
But after validating the spinner visibility I am validating the invisibility of the same element.
But the element still waits more than 30-40 seconds even if I have given 10 seconds. Then after around 40 seconds it is not throwing any error and continues to execute the script without any exception
public void Spinner_Check(string locator, string locatorvalue)
{
int count = 1;
WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
waits.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(LocatorSelect(locator, locatorvalue)));
while (count > 0)
{
waits.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath(locatorvalue)));
IList<IWebElement> spinner_element = driver.FindElements(By.XPath(locatorvalue));
int size = spinner_element.Count;
if (size != 1)
{
count = 0;
WriteLine("pass", "Spinner is dismissed for the page");
break;
}
}
}
So how can I avoid that much wait time and execute the script soon after the spinner is dismissed from the page.
Few observations in the script:
When I inspect the html, when the element is visible, I could see style of the display attribute is 'Block'.But after spinner is dismissed from the UI, I could see, xpath showing no element in the search area : //iframe/parent::body//div[text()='Loading..']
For debugging purpose I had set wait for element visible after spinner dismissed from the page. Then I could see timeout exception and NoSuchElement exception triggered.