88import org .openqa .selenium .WebElement ;
99import org .openqa .selenium .support .ui .FluentWait ;
1010
11+ import java .time .Duration ;
1112import java .util .List ;
1213import java .util .regex .Matcher ;
1314import java .util .regex .Pattern ;
@@ -153,7 +154,10 @@ public static class SubTree extends Component<Component<?>.ElementCache>
153154 // Second <div> under the <li>
154155 private final WebElement _children = Locator .xpath ("./div[2]" ).findWhenNeeded (this );
155156
156- private final FluentWait <Object > toggleWait = new FluentWait <>(new Object ());
157+ private FluentWait <Object > toggleWait ()
158+ {
159+ return new FluentWait <>(new Object ()).withTimeout (Duration .ofSeconds (1 ));
160+ }
157161
158162 SubTree (WebElement el )
159163 {
@@ -266,7 +270,7 @@ private void expand()
266270 if (waitForToggle () != DirExpansionState .OPEN )
267271 {
268272 _toggleArrow .click ();
269- toggleWait .withMessage (() -> String .format ("Waiting for '%s' to expand." , getName ()))
273+ toggleWait () .withMessage (() -> String .format ("Waiting for '%s' to expand." , getName ()))
270274 .until (o -> getState () == DirExpansionState .OPEN );
271275 }
272276 }
@@ -276,7 +280,7 @@ private void collapse()
276280 if (waitForToggle () != DirExpansionState .CLOSED )
277281 {
278282 _toggleArrow .click ();
279- toggleWait .withMessage (() -> String .format ("Waiting for '%s' to collapse." , getName ()))
283+ toggleWait () .withMessage (() -> String .format ("Waiting for '%s' to collapse." , getName ()))
280284 .until (o -> getState () == DirExpansionState .CLOSED );
281285 }
282286 }
@@ -288,7 +292,7 @@ private boolean isActive()
288292
289293 private DirExpansionState waitForToggle ()
290294 {
291- return toggleWait .withMessage (() -> String .format ("Waiting for '%s' to animate." , getName ()))
295+ return toggleWait () .withMessage (() -> String .format ("Waiting for '%s' to animate." , getName ()))
292296 .until (o -> {
293297 DirExpansionState state = getState ();
294298 if (state == DirExpansionState .ANIMATING )
0 commit comments