0
0
Selenium Javatesting~10 mins

Unexpected alert handling 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().alerts()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after alert()
Using alert without switchTo()
2fill in blank
medium

Complete the code to accept the unexpected alert.

Selenium Java
driver.switchTo().alert().[1]();
Drag options to blanks, or click blank then click option'
Aaccept
Bdismiss
Cclose
DsendKeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept()
Trying to close() the alert
3fill in blank
hard

Fix the error in the code to get alert text.

Selenium Java
String alertText = driver.switchTo().alert().[1]();
Drag options to blanks, or click blank then click option'
Atext
Bget_text
CgetText
DgetAlertText
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python style get_text
Using non-existent methods like getAlertText
4fill in blank
hard

Fill both blanks to handle alert and print its text.

Selenium Java
Alert alert = driver.[1]();
System.out.println(alert.[2]());
Drag options to blanks, or click blank then click option'
AswitchTo().alert()
Baccept
CgetText
Ddismiss
Attempts:
3 left
💡 Hint
Common Mistakes
Using accept() instead of getText() when printing
Not switching to alert before accessing it
5fill in blank
hard

Fill all three blanks to handle unexpected alert by getting text, accepting it, and printing the message.

Selenium Java
Alert alert = driver.[1]();
String message = alert.[2]();
alert.[3]();
System.out.println(message);
Drag options to blanks, or click blank then click option'
AswitchTo().alert()
BgetText
Caccept
Ddismiss
Attempts:
3 left
💡 Hint
Common Mistakes
Calling accept() before getText() causing lost message
Using dismiss() instead of accept()