package com.specmate.uitests.pagemodel;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;

public class UITestUtil {
	public static void waitForModalToDisappear(WebDriver driver) {
		By modalLocator = By.id("loading-modal");
		/*
		 * 	If modal is present, wait till it vanishes
		 * 	If it modal is not present resume
		 * */
		
		boolean modalDisplayed = true;
    	int counter = 6;
    	driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    	do {
    		try {
    			counter--;
    			modalDisplayed = ((counter>0) && driver.findElement(modalLocator).isDisplayed());
    		} catch (NoSuchElementException e) {
    			modalDisplayed = false;
    		}
    	} while(modalDisplayed);
    	// Change timeout back to the defined value
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
	}
}
@@ -161,16 +161,76 @@
 ption;%0D%0A
+import org.openqa.selenium.StaleElementReferenceException;%0D%0A
 import o
@@ -807,16 +807,102 @@
 ception 
+ne) %7B%0D%0A    %09%09%09modalDisplayed = false;%0D%0A    %09%09%7D catch (StaleElementReferenceException s
 e) %7B%0D%0A  
@@ -1095,17 +1095,13 @@
 ONDS);%0D%0A
-%09%09%0D%0A
 %09%7D%0D%0A%7D

Add Stale element reference