0
0
Selenium Javatesting~10 mins

Async script execution 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 execute an asynchronous JavaScript script using Selenium WebDriver.

Selenium Java
JavascriptExecutor js = (JavascriptExecutor) driver;
js.[1]("window.setTimeout(arguments[arguments.length - 1], 500);", new Object[] {});
Drag options to blanks, or click blank then click option'
AexecuteJavaScript
BexecuteAsyncScript
CexecuteScript
DrunAsyncScript
Attempts:
3 left
💡 Hint
Common Mistakes
Using executeScript instead of executeAsyncScript causes the script to run synchronously.
2fill in blank
medium

Complete the code to pass a callback function to the asynchronous JavaScript executed by Selenium.

Selenium Java
Object result = js.executeAsyncScript("var callback = arguments[[1]]; window.setTimeout(function() { callback('done'); }, 300);");
Drag options to blanks, or click blank then click option'
A0
B1
Carguments.length - 1
Darguments.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 as the index causes the callback to be undefined.
3fill in blank
hard

Fix the error in the asynchronous script execution code by choosing the correct method call.

Selenium Java
js.[1]("window.setTimeout(arguments[arguments.length - 1], 1000);");
Drag options to blanks, or click blank then click option'
AexecuteAsyncScript
BexecuteScript
CrunScript
DrunAsync
Attempts:
3 left
💡 Hint
Common Mistakes
Using executeScript causes the script to run synchronously and not wait for the callback.
4fill in blank
hard

Fill both blanks to correctly execute an async script that returns a value after delay.

Selenium Java
Object result = js.[1]("var callback = arguments[[2]]; setTimeout(function() { callback('success'); }, 200);");
Drag options to blanks, or click blank then click option'
AexecuteAsyncScript
BexecuteScript
Carguments.length - 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using executeScript instead of executeAsyncScript.
Using 0 instead of arguments.length - 1 for callback index.
5fill in blank
hard

Fill all three blanks to create a map of word lengths (keys) to lengths plus one (values), filtering only words longer than 4 characters.

Selenium Java
Map<Integer, Integer> lengths = words.stream()
    .filter(word -> word.length() [1] 4)
    .collect(Collectors.toMap(word -> word.[2], word -> word.length() [3] 1));
Drag options to blanks, or click blank then click option'
A>
Blength()
C+
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in filter.
Using word instead of word.length() for the key.
Using '-' instead of '+' for increment.