Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to switch to the alert.
Selenium Java
Alert alert = driver.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after alert()
Using switchTo.alert without parentheses
✗ Incorrect
In Selenium Java, to switch to an alert, you use driver.switchTo().alert() with parentheses to get the Alert object.
2fill in blank
mediumComplete the code to accept the alert.
Selenium Java
alert.[1](); Drag options to blanks, or click blank then click option'
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
✗ Incorrect
To accept an alert in Selenium Java, you call the accept() method on the Alert object.
3fill in blank
hardFix the error in the code to dismiss the alert.
Selenium Java
alert.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including parentheses inside the blank token
Using accept() instead of dismiss() to cancel the alert
✗ Incorrect
The dismiss() method is called without parentheses in the code, but in Java it must be called with parentheses. The correct code is alert.dismiss(); so the blank must be 'dismiss'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to accept the alert
Forgetting to call getText() as a method
✗ Incorrect
To get the alert text, use getText(). To accept the alert, use accept(). Both are methods called with parentheses.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to confirm the alert
Forgetting parentheses on method calls
✗ Incorrect
To send text to a prompt alert, use sendKeys("text"). To get the alert text, use getText(). To accept the alert, use accept(). All are methods called with parentheses.