2424import org .openqa .selenium .remote .RemoteWebElement ;
2525import org .openqa .selenium .support .ui .WebDriverWait ;
2626
27+ import static org .openqa .selenium .support .ui .ExpectedConditions .alertIsPresent ;
2728import static org .openqa .selenium .support .ui .ExpectedConditions .titleIs ;
2829import static org .openqa .selenium .support .ui .ExpectedConditions .visibilityOfElementLocated ;
2930
@@ -172,6 +173,8 @@ void testHandleUserPrompt() {
172173
173174 driver .findElement (By .id ("alert" )).click ();
174175
176+ wait .until (alertIsPresent ());
177+
175178 browsingContext .handleUserPrompt ();
176179
177180 Assertions .assertTrue (driver .getPageSource ().contains ("Testing Alerts and Stuff" ));
@@ -185,7 +188,9 @@ void testAcceptUserPrompt() {
185188
186189 driver .findElement (By .id ("alert" )).click ();
187190
188- browsingContext .handleUserPrompt ("true" );
191+ wait .until (alertIsPresent ());
192+
193+ browsingContext .handleUserPrompt (true );
189194
190195 Assertions .assertTrue (driver .getPageSource ().contains ("Testing Alerts and Stuff" ));
191196 }
@@ -198,7 +203,9 @@ void testDismissUserPrompt() {
198203
199204 driver .findElement (By .id ("alert" )).click ();
200205
201- browsingContext .handleUserPrompt ("true" );
206+ wait .until (alertIsPresent ());
207+
208+ browsingContext .handleUserPrompt (false );
202209
203210 Assertions .assertTrue (driver .getPageSource ().contains ("Testing Alerts and Stuff" ));
204211 }
@@ -211,6 +218,8 @@ void testPassUserTextToUserPrompt() {
211218
212219 driver .findElement (By .id ("prompt-with-default" )).click ();
213220
221+ wait .until (alertIsPresent ());
222+
214223 String userText = "Selenium automates browsers" ;
215224 browsingContext .handleUserPrompt (true , userText );
216225
@@ -225,6 +234,8 @@ void testDismissUserPromptWithText() {
225234
226235 driver .findElement (By .id ("prompt-with-default" )).click ();
227236
237+ wait .until (alertIsPresent ());
238+
228239 String userText = "Selenium automates browsers" ;
229240 browsingContext .handleUserPrompt (false , userText );
230241
0 commit comments