0
0
Selenium Javatesting~10 mins

Alert accept and dismiss in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to switch to the alert.

Selenium Java
Alert alert = driver.[1]();
Drag options to blanks, or click blank then click option'
AswitchTo.alert
BswitchTo().alert
CswitchTo.alert()
DswitchTo().alert()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after alert()
Using switchTo.alert without parentheses
2fill in blank
medium

Complete the code to accept the alert.

Selenium Java
alert.[1]();
Drag options to blanks, or click blank then click option'
Aclose
Bdismiss
Caccept
DsendKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to accept the alert
Trying to use close() which is not valid for alerts
3fill in blank
hard

Fix the error in the code to dismiss the alert.

Selenium Java
alert.[1]();
Drag options to blanks, or click blank then click option'
Adismiss
Bdismiss()
Caccept
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Including parentheses inside the blank token
Using accept() instead of dismiss() to cancel the alert
4fill in blank
hard

Fill both blanks to get alert text and accept it.

Selenium Java
String text = alert.[1]();
alert.[2]();
Drag options to blanks, or click blank then click option'
AgetText
Baccept
Cdismiss
DsendKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to accept the alert
Forgetting to call getText() as a method
5fill in blank
hard

Fill all three blanks to send text to prompt alert, get text, and accept it.

Selenium Java
alert.[1]("Hello");
String msg = alert.[2]();
alert.[3]();
Drag options to blanks, or click blank then click option'
AsendKeys
BgetText
Caccept
Ddismiss
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to confirm the alert
Forgetting parentheses on method calls