Is it possible to utilize Selenium to open a URL and execute a script? If so, how can I pass a value back to my Java program when the 'Escape' key is pressed?
This particular functionality in my code involves the following Java program:
JavascriptExecutor js = (JavascriptExecutor) driver;
String content = new String(Files.readAllBytes(Paths.get("xp_simple.js")));
String str = (String) js.executeScript(content);
System.out.println("Returned from js : " + str);
The associated javascript string that gets passed is as follows:
var pageName='value from webpage';
window.addEventListener('keydown', function (zEvent) {
if (zEvent.key === 'Escape') {
console.log("Escape is pressed");
return getSG()
}
} );
function getSG() {
return pageName;
};
An ongoing issue manifests as control not remaining until the Escape key is pressed. Instead, the program immediately reverts back to Java with the value of 'str' being null.