Bird
0
0

Which of the following is the correct way to cast a WebDriver instance to JavascriptExecutor in Selenium Java?

easy📝 Syntax Q12 of 15
Selenium Java - JavaScriptExecutor
Which of the following is the correct way to cast a WebDriver instance to JavascriptExecutor in Selenium Java?
AJavascriptExecutor js = driver.executeScript();
BJavascriptExecutor js = driver.getJavascriptExecutor();
CJavascriptExecutor js = new JavascriptExecutor(driver);
DJavascriptExecutor js = (JavascriptExecutor) driver;
Step-by-Step Solution
Solution:
  1. Step 1: Recall the casting syntax in Java

    To use JavascriptExecutor, you cast the WebDriver instance like this: (JavascriptExecutor) driver.
  2. Step 2: Check each option

    JavascriptExecutor js = (JavascriptExecutor) driver; uses correct casting syntax. The other options are invalid method calls or constructors.
  3. Final Answer:

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

    Cast driver to JavascriptExecutor using (JavascriptExecutor) [OK]
Quick Trick: Casting uses (JavascriptExecutor) before driver [OK]
Common Mistakes:
MISTAKES
  • Using non-existent methods like getJavascriptExecutor()
  • Trying to instantiate JavascriptExecutor with new keyword
  • Calling executeScript() without casting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes