Complete the code to execute JavaScript that returns the page title.
String title = (String) ((JavascriptExecutor) driver).executeScript([1]);JavaScript execution requires the return keyword to get the value back to Java.
Complete the code to scroll the page down by 500 pixels using JavaScript.
((JavascriptExecutor) driver).executeScript([1]);window.scrollBy(0, 500); scrolls vertically down by 500 pixels.
Fix the error in JavaScript execution that tries to click an element but fails.
((JavascriptExecutor) driver).executeScript([1], element);In JavaScript execution, arguments[0] refers to the passed element.
Fill both blanks to return the inner text of an element and trim whitespace.
String text = (String) ((JavascriptExecutor) driver).executeScript("return arguments[0].[1].[2]();", element);
textContent may include hidden text.strip() is not a JavaScript string method.innerText gets visible text, and trim() removes extra spaces.
Fill all three blanks to create a map of element IDs to their text content using JavaScript execution.
Map<String, String> texts = (Map<String, String>) ((JavascriptExecutor) driver).executeScript( "let result = {}; for(let el of arguments[0]) { result[el.[1]] = el.[2].[3](); } return result;", elements );
textContent instead of innerText includes hidden text.trim() leaves extra spaces.Use id for keys, innerText for text, and trim() to clean spaces.
