File tree Expand file tree Collapse file tree 2 files changed +38
-10
lines changed
src/org/openqa/selenium/support/ui
test/org/openqa/selenium/support/ui Expand file tree Collapse file tree 2 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -1369,16 +1369,7 @@ public static ExpectedCondition<Boolean> invisibilityOfAllElements(
1369
1369
1370
1370
@ Override
1371
1371
public Boolean apply (WebDriver webDriver ) {
1372
- for (WebElement element : elements ) {
1373
- try {
1374
- if (element .isDisplayed ()) {
1375
- return false ;
1376
- }
1377
- } catch (StaleElementReferenceException ignored ) {
1378
- // We can assume a stale element isn't displayed.
1379
- }
1380
- }
1381
- return true ;
1372
+ return elements .stream ().allMatch (ExpectedConditions ::isInvisible );
1382
1373
}
1383
1374
1384
1375
@ Override
@@ -1388,6 +1379,36 @@ public String toString() {
1388
1379
};
1389
1380
}
1390
1381
1382
+ /**
1383
+ * An expectation for checking the element to be invisible
1384
+ *
1385
+ * @param element used to check its invisibility
1386
+ * @return Boolean true when elements is not visible anymore
1387
+ */
1388
+ public static ExpectedCondition <Boolean > invisibilityOf (final WebElement element ) {
1389
+ return new ExpectedCondition <Boolean >() {
1390
+
1391
+ @ Override
1392
+ public Boolean apply (WebDriver webDriver ) {
1393
+ return isInvisible (element );
1394
+ }
1395
+
1396
+ @ Override
1397
+ public String toString () {
1398
+ return "invisibility of " + element ;
1399
+ }
1400
+ };
1401
+ }
1402
+
1403
+ private static boolean isInvisible (final WebElement element ) {
1404
+ try {
1405
+ return !element .isDisplayed ();
1406
+ } catch (StaleElementReferenceException ignored ) {
1407
+ // We can assume a stale element isn't displayed.
1408
+ return true ;
1409
+ }
1410
+ }
1411
+
1391
1412
/**
1392
1413
* An expectation with the logical or condition of the given list of conditions.
1393
1414
*
Original file line number Diff line number Diff line change 31
31
import static org .openqa .selenium .support .ui .ExpectedConditions .attributeToBe ;
32
32
import static org .openqa .selenium .support .ui .ExpectedConditions .attributeToBeNotEmpty ;
33
33
import static org .openqa .selenium .support .ui .ExpectedConditions .elementSelectionStateToBe ;
34
+ import static org .openqa .selenium .support .ui .ExpectedConditions .invisibilityOf ;
34
35
import static org .openqa .selenium .support .ui .ExpectedConditions .invisibilityOfAllElements ;
35
36
import static org .openqa .selenium .support .ui .ExpectedConditions .not ;
36
37
import static org .openqa .selenium .support .ui .ExpectedConditions .numberOfElementsToBe ;
@@ -811,6 +812,12 @@ public void waitingForAllElementsInvisibilityWhenElementsAreVisible() {
811
812
wait .until (invisibilityOfAllElements (Arrays .asList (mockElement )));
812
813
}
813
814
815
+ @ Test (expected = TimeoutException .class )
816
+ public void waitingForElementInvisibilityWhenElementIsVisible () {
817
+ when (mockElement .isDisplayed ()).thenReturn (true );
818
+ wait .until (invisibilityOf (mockElement ));
819
+ }
820
+
814
821
@ Test (expected = TimeoutException .class )
815
822
public void waitingForTextToBePresentInElementLocatedThrowsTimeoutExceptionWhenTextNotPresent () {
816
823
String testSelector = "testSelector" ;
You can’t perform that action at this time.
0 commit comments