Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to switch to the prompt 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 alerts() instead of alert()
Trying to access alert as a property without method call
✗ Incorrect
The correct method to switch to an alert in Selenium Java is switchTo().alert() with parentheses to call the method.
2fill in blank
mediumComplete the code to send text to the prompt alert.
Selenium Java
alert.[1]("Hello World");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setText or type which are not valid Alert methods
Trying to send keys directly to driver instead of alert
✗ Incorrect
The method to enter text into a prompt alert in Selenium Java is sendKeys().
3fill in blank
hardFix the error in the code to accept the prompt alert after entering text.
Selenium Java
alert.sendKeys("Test"); alert.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() which cancels the alert instead of accepting
Trying to use close() which is not a method of Alert
✗ Incorrect
To accept a prompt alert after entering text, use the accept() method.
4fill in blank
hardFill both blanks to correctly handle a prompt alert by sending text and accepting it.
Selenium Java
Alert alert = driver.[1](); alert.[2]("Selenium"); alert.accept();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using setText instead of sendKeys
Using dismiss instead of sendKeys for entering text
✗ Incorrect
First, switch to the alert using switchTo().alert(), then send text using sendKeys(). Finally, accept the alert.
5fill in blank
hardFill all three blanks to switch to a prompt alert, send text, and accept it.
Selenium Java
Alert alert = driver.[1](); alert.[2]("Test123"); alert.[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept()
Forgetting parentheses on switchTo().alert()
✗ Incorrect
The correct sequence is to switch to the alert with switchTo().alert(), send text with sendKeys(), and accept the alert with accept().