0
0
Selenium Javatesting~10 mins

Clicking via JavaScript in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a JavaScriptExecutor instance from the WebDriver.

Selenium Java
JavascriptExecutor js = (JavascriptExecutor) [1];
Drag options to blanks, or click blank then click option'
Adriver
BWebDriver
Cnew JavascriptExecutor()
Djs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new JavascriptExecutor()' which is invalid.
Using the class name 'WebDriver' instead of the instance.
2fill in blank
medium

Complete the code to click an element using JavaScriptExecutor.

Selenium Java
js.executeScript("[1]", element);
Drag options to blanks, or click blank then click option'
Aclick(arguments[0])
Barguments[0].click()
Celement.click()
Darguments[0].click();
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the semicolon causes syntax errors.
Trying to call click() directly on element in JavaScript string.
3fill in blank
hard

Fix the error in the JavaScriptExecutor click code by completing the missing part.

Selenium Java
js.executeScript("arguments[0].[1]();", element);
Drag options to blanks, or click blank then click option'
Aclicks
Bclicked
Cclick
Dclicking
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'clicks' or 'clicked'.
Adding extra suffixes to the method name.
4fill in blank
hard

Fill both blanks to scroll an element into view and then click it using JavaScriptExecutor.

Selenium Java
js.executeScript("arguments[0].[1](); arguments[0].[2]();", element);
Drag options to blanks, or click blank then click option'
AscrollIntoView
Bclick
CscrollTo
Dfocus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scrollTo' instead of 'scrollIntoView' which is not a method on elements.
Using 'focus' instead of 'click' for clicking.
5fill in blank
hard

Fill all three blanks to define a method that clicks an element via JavaScriptExecutor.

Selenium Java
public void [1](WebElement element) {
    JavascriptExecutor js = (JavascriptExecutor) [2];
    js.executeScript("arguments[0].[3]();", element);
}
Drag options to blanks, or click blank then click option'
AclickElement
Bdriver
Cclick
DexecuteScript
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names.
Using wrong variable names for WebDriver.
Using wrong JavaScript method names.