Bird
0
0

Identify the error in this code snippet for entering text into a prompt alert: ```java Alert alert = driver.switchTo().alert(); alert.sendkeys("Hello"); alert.accept(); ```

medium📝 Debug Q6 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Identify the error in this code snippet for entering text into a prompt alert: ```java Alert alert = driver.switchTo().alert(); alert.sendkeys("Hello"); alert.accept(); ```
AMethod name should be sendKeys with capital K
Balert.accept() should be alert.dismiss()
Cdriver.switchTo().alert() is incorrect
DsendKeys cannot be used on alerts
Step-by-Step Solution
Solution:
  1. Step 1: Check method names for alert input

    The method to send text is sendKeys() with capital K, not sendkeys().
  2. Step 2: Verify other method calls

    accept() is correct to confirm the alert; switchTo().alert() is valid.
  3. Final Answer:

    Method name should be sendKeys with capital K -> Option A
  4. Quick Check:

    Method names are case-sensitive in Java [OK]
Quick Trick: Java method names are case-sensitive: sendKeys not sendkeys [OK]
Common Mistakes:
  • Using wrong case in method names
  • Confusing accept() with dismiss()
  • Thinking sendKeys() is invalid on alerts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes