Challenge - 5 Problems
Prompt Alert Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output after entering text in a prompt alert?
Consider this Selenium Java code snippet that handles a prompt alert. What will be the printed output after execution?
Selenium Java
WebDriver driver = new ChromeDriver(); driver.get("https://example.com/prompt"); Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Hello"); prompt.accept(); String result = driver.findElement(By.id("result")).getText(); System.out.println(result);
Attempts:
2 left
💡 Hint
The prompt alert accepts the input text and the page updates the element with id 'result' to show the entered text.
✗ Incorrect
The prompt alert receives the text 'Hello' via sendKeys, then accept() confirms it. The page updates the element with id 'result' to display the entered text, so printing its text outputs 'Hello'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies prompt alert text entry?
You want to verify that entering 'Test123' in a prompt alert updates the page text correctly. Which assertion is correct?
Selenium Java
Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Test123"); prompt.accept(); String actualText = driver.findElement(By.id("output")).getText();
Attempts:
2 left
💡 Hint
You want to check exact match of the entered text.
✗ Incorrect
assertEquals("Test123", actualText) checks that the page text exactly matches the entered prompt text, ensuring correct input handling.
🔧 Debug
advanced2:30remaining
Why does this prompt alert text entry code fail with UnhandledAlertException?
Review this code snippet. It throws UnhandledAlertException at runtime. What is the cause?
Selenium Java
driver.get("https://example.com/prompt"); WebElement button = driver.findElement(By.id("showPrompt")); button.click(); String alertText = driver.switchTo().alert().getText(); System.out.println(alertText); driver.findElement(By.id("inputField")).sendKeys("Hello"); driver.switchTo().alert().accept();
Attempts:
2 left
💡 Hint
You cannot interact with page elements while an alert is open.
✗ Incorrect
When a prompt alert is open, Selenium cannot interact with page elements. The code tries to sendKeys to an element while alert is still open, causing UnhandledAlertException.
❓ framework
advanced2:30remaining
Which Selenium Java code snippet correctly enters text into a prompt alert and verifies the result?
Select the code snippet that correctly handles a prompt alert by entering 'QA Test', accepting it, and asserting the page shows the entered text.
Attempts:
2 left
💡 Hint
You must send keys before accepting the alert.
✗ Incorrect
Option A correctly sends keys to the alert, accepts it, then verifies the page text. Other options send keys after accept/dismiss or try to send keys to page elements, causing errors.
🧠 Conceptual
expert3:00remaining
What is the correct sequence to handle a prompt alert text entry in Selenium Java?
Arrange the steps in the correct order to enter text into a prompt alert and confirm it using Selenium Java.
Attempts:
2 left
💡 Hint
You must switch to alert before sending keys and accept after sending keys.
✗ Incorrect
The correct order is to switch to alert, send keys, accept alert, then verify page result. Other orders cause errors or incorrect behavior.