Bird
0
0

Find the issue in this code snippet:

medium📝 Debug Q7 of 15
Selenium Java - JavaScriptExecutor
Find the issue in this code snippet:
WebElement element = driver.findElement(By.xpath("//div[@class='content']"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", "element");
APassing element as a string instead of WebElement
BIncorrect XPath syntax
CMissing semicolon in JavaScript code
DNo issue, code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Check arguments passed to executeScript

    It expects a WebElement, but a string "element" is passed.
  2. Step 2: Understand impact

    Passing string causes JavaScript error; element must be passed directly.
  3. Final Answer:

    Passing element as a string instead of WebElement -> Option A
  4. Quick Check:

    Pass WebElement, not string, to executeScript [OK]
Quick Trick: Pass WebElement, not string, to executeScript [OK]
Common Mistakes:
  • Passing element name as string
  • Assuming XPath is wrong
  • Ignoring JavaScript semicolon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes