Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to scroll the element into view using JavaScriptExecutor.
Selenium Java
JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].[1](true);", element);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scroll' instead of 'scrollIntoView' causes JavaScript errors.
Trying to call 'executeScript' on the element instead of the JavascriptExecutor.
✗ Incorrect
The scrollIntoView method scrolls the page until the element is visible.
2fill in blank
mediumComplete the code to find the element by its ID before scrolling it into view.
Selenium Java
WebElement element = driver.findElement(By.[1]("footer"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'className' or 'name' when the element's ID is needed.
Using 'xpath' unnecessarily for simple ID selection.
✗ Incorrect
To find an element by its ID attribute, use By.id.
3fill in blank
hardFix the error in the JavaScriptExecutor casting to scroll the element into view.
Selenium Java
JavascriptExecutor js = ([1]) driver; js.executeScript("arguments[0].scrollIntoView(true);", element);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Casting to
WebDriver or WebElement causes compile errors.Casting to
RemoteWebDriver is not necessary here.✗ Incorrect
You must cast the driver to JavascriptExecutor to use executeScript.
4fill in blank
hardFill both blanks to scroll the element into view and then click it.
Selenium Java
JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].[1](true);", element); element.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
submit or sendKeys instead of click.Forgetting to scroll before clicking may cause element not clickable errors.
✗ Incorrect
First, scroll the element into view, then perform a click action on it.
5fill in blank
hardFill all three blanks to scroll an element found by CSS selector into view and then click it.
Selenium Java
WebElement element = driver.findElement(By.[1](".menu-item")); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].[2](true);", element); element.[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
id instead of cssSelector for the selector.Calling
click before scrolling causes errors.✗ Incorrect
Find the element by CSS selector, scroll it into view, then click it.