|
9 | 9 | import org.apache.commons.lang.StringUtils; |
10 | 10 | import org.apache.logging.log4j.LogManager; |
11 | 11 | import org.apache.logging.log4j.Logger; |
12 | | -import org.openqa.selenium.JavascriptExecutor; |
13 | | -import org.openqa.selenium.StaleElementReferenceException; |
14 | | -import org.openqa.selenium.WebDriver; |
15 | | -import org.openqa.selenium.WebElement; |
| 12 | +import org.openqa.selenium.*; |
| 13 | +import org.openqa.selenium.support.ui.ExpectedCondition; |
16 | 14 | import org.openqa.selenium.support.ui.ExpectedConditions; |
17 | 15 | import org.openqa.selenium.support.ui.WebDriverWait; |
18 | 16 | import ru.yandex.qatools.htmlelements.element.HtmlElement; |
19 | 17 | import ru.yandex.qatools.htmlelements.element.TypifiedElement; |
20 | 18 | import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader; |
21 | 19 |
|
| 20 | +import javax.annotation.Nullable; |
22 | 21 | import java.lang.annotation.Annotation; |
23 | 22 | import java.lang.reflect.Field; |
24 | 23 | import java.util.List; |
@@ -115,6 +114,15 @@ private void waitForExpectedVisibleElements(Object pageObject, String visibleGro |
115 | 114 | waitForObjectToBeVisible(obj); |
116 | 115 | } |
117 | 116 | } |
| 117 | + } else if (annotation instanceof Invisible) { |
| 118 | + field.setAccessible(true); |
| 119 | + Object obj = field.get(pageObject); |
| 120 | + if (obj instanceof WebElement) { |
| 121 | + wait.until(invisibilityOfElement((WebElement)obj)); |
| 122 | + } |
| 123 | + else if(obj instanceof TypifiedElement ){ |
| 124 | + wait.until(invisibilityOfElement(((TypifiedElement) obj).getWrappedElement())); |
| 125 | + } |
118 | 126 | } |
119 | 127 | } |
120 | 128 | } |
@@ -151,6 +159,31 @@ private void waitForObjectToBeVisible(Object obj) throws IllegalArgumentExceptio |
151 | 159 | } |
152 | 160 | } |
153 | 161 |
|
| 162 | + private void waitForInvisibleElement(WebElement element){ |
| 163 | + wait.until(invisibilityOfElement(element)); |
| 164 | + } |
| 165 | + |
| 166 | + private ExpectedCondition<Boolean> invisibilityOfElement(WebElement element){ |
| 167 | + return new ExpectedCondition<Boolean>() { |
| 168 | + @Nullable |
| 169 | + @Override |
| 170 | + public Boolean apply(WebDriver input) { |
| 171 | + try { |
| 172 | + return !element.isDisplayed(); |
| 173 | + } catch (NoSuchElementException var3) { |
| 174 | + return Boolean.valueOf(true); |
| 175 | + } catch (StaleElementReferenceException var4) { |
| 176 | + return Boolean.valueOf(true); |
| 177 | + } |
| 178 | + } |
| 179 | + public String toString() { |
| 180 | + return "element to no longer be visible: " + element; |
| 181 | + } |
| 182 | + }; |
| 183 | + |
| 184 | + } |
| 185 | + |
| 186 | + |
154 | 187 | /** |
155 | 188 | * Will wait up to ~10 seconds for the document to be ready. |
156 | 189 | */ |
|
0 commit comments