Skip to content
CodeKruPro

Type into a prompt alert

Automation taskMediumAsked in: Capgemini, Infosys, TCS, Wipro

"How do you type into a JavaScript prompt?" Switch to the alert, send keys to it and accept. Then read the result on the page to prove the text arrived.

Handle Prompt Alert

Handle Prompt Alert

A prompt alert has a text input field. Use alert.sendKeys() to type into it before accepting.

On the Alerts page, clicking "Show Prompt" shows a prompt with default text "Testkru". The result appears in id="promptResult".

Task:

  1. Navigate to https://testkru.com/Interactions/Alerts
  2. Click "Show Prompt"
  3. Clear the default text and type Selenium
  4. Accept the prompt
  5. Print the result from the page

Expected output:

Result: You entered: Selenium