A prompt alert is a popup dialog box that asks the user to enter some text input before continuing. Selenium can interact with it by switching to the alert and sending text.
Click to reveal answer
beginner
How do you switch to a prompt alert in Selenium Java?
Use driver.switchTo().alert() to switch the WebDriver's focus to the alert popup.
Click to reveal answer
beginner
Which method is used to enter text into a prompt alert in Selenium Java?
The method sendKeys(String text) is used to enter text into the prompt alert.
Click to reveal answer
intermediate
What is the correct sequence to handle a prompt alert with text entry and accept it?
1. Switch to alert with driver.switchTo().alert(). 2. Enter text using sendKeys(). 3. Accept the alert with accept().
Click to reveal answer
beginner
Why is it important to switch to the alert before interacting with it?
Because alerts are separate from the main page DOM, Selenium must switch focus to the alert to interact with it. Otherwise, commands will fail.
Click to reveal answer
Which Selenium method is used to enter text into a prompt alert?
AsendKeys()
BsetText()
Ctype()
DinputText()
✗ Incorrect
The correct method to enter text into a prompt alert is sendKeys().
What must you do before sending text to a prompt alert in Selenium?
ASwitch to the alert using driver.switchTo().alert()
BClick on the alert element
CRefresh the page
DClose the alert first
✗ Incorrect
You must switch to the alert using driver.switchTo().alert() before interacting with it.
After entering text in a prompt alert, which method accepts the alert?
Adismiss()
Baccept()
Cclose()
Dsubmit()
✗ Incorrect
The accept() method clicks the OK button on the alert.
What happens if you try to sendKeys() without switching to the alert first?
AText is entered successfully
BNo effect, alert stays open
CThrows NoAlertPresentException
DPage reloads
✗ Incorrect
Selenium throws NoAlertPresentException because it is not focused on the alert.
Which of these is NOT a valid method for alert handling in Selenium?
Aaccept()
Bdismiss()
CsendKeys()
Dclick()
✗ Incorrect
click() is not a method for alert handling; alerts use accept(), dismiss(), and sendKeys().
Explain the steps to enter text into a prompt alert and accept it using Selenium Java.
Think about how Selenium focuses on alerts and how to interact with them.
You got /3 concepts.
Why is switching to the alert necessary before sending text or accepting it?
Consider how Selenium interacts with different parts of the browser.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of a prompt alert in Selenium testing?
easy
A. To allow the user to enter text in a popup window
B. To display a message without user input
C. To confirm an action with OK or Cancel buttons only
D. To automatically close the browser window
Solution
Step 1: Understand what a prompt alert is
A prompt alert is a popup that asks the user to enter some text.
Step 2: Compare with other alert types
Unlike simple alerts or confirmation alerts, prompt alerts allow text input.
Final Answer:
To allow the user to enter text in a popup window -> Option A
Quick Check:
Prompt alert = text input popup [OK]
Hint: Prompt alerts let users type text in popups [OK]
Common Mistakes:
Confusing prompt alerts with simple alerts
Thinking prompt alerts only show messages
Assuming prompt alerts cannot accept input
2. Which Selenium Java method is used to enter text into a prompt alert?
easy
A. alert.sendKeys("text")
B. alert.enterText("text")
C. alert.type("text")
D. alert.setText("text")
Solution
Step 1: Recall Selenium Alert interface methods
The Alert interface provides sendKeys() to input text into prompt alerts.
Step 2: Verify method names
Only sendKeys() is the correct method; others do not exist in Selenium Alert API.
Final Answer:
alert.sendKeys("text") -> Option A
Quick Check:
Use sendKeys() to input text [OK]
Hint: Use sendKeys() to type text in prompt alerts [OK]
Common Mistakes:
Using non-existent methods like enterText()
Trying to use setText() which is not in Alert API
Confusing sendKeys() with WebElement methods
3. What will happen if you run this Selenium Java code snippet?