Bird
0
0

Which of the following is the correct way to cast WebDriver to JavaScriptExecutor in Selenium Java?

easy📝 Syntax Q3 of 15
Selenium Java - JavaScriptExecutor
Which of the following is the correct way to cast WebDriver to JavaScriptExecutor in Selenium Java?
AJavaScriptExecutor js = (JavaScriptExecutor) driver;
BJavaScriptExecutor js = (JavascriptExecutor) driver;
CJavascriptExecutor js = (JavascriptExecutor) driver;
DJavascriptExecutor js = (JavaScriptExecutor) driver;
Step-by-Step Solution
Solution:
  1. Step 1: Check correct interface name spelling

    The correct interface name is JavascriptExecutor with lowercase 's' in 'script'.
  2. Step 2: Confirm casting syntax

    Casting requires the interface name exactly as declared; JavascriptExecutor js = (JavascriptExecutor) driver; uses correct spelling and casting.
  3. Final Answer:

    JavascriptExecutor js = (JavascriptExecutor) driver; -> Option C
  4. Quick Check:

    Correct casting syntax = A [OK]
Quick Trick: Interface name is JavascriptExecutor, not JavaScriptExecutor [OK]
Common Mistakes:
  • Capitalizing 'S' in JavascriptExecutor incorrectly
  • Using wrong interface name
  • Missing cast parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes