Visit this link for proofs
Running a script in the browser console on the specified page:
let img = document.querySelector('.subscribe'),
style = img.currentStyle || window.getComputedStyle(img, false),
bi = style.backgroundImage.slice(4, -1).replace(/"/g, "");
Type 'bi' in the console and press enter. Expecting URL to be: "https://www.companyfolders.com/images/skin/bgr_header.png"
However, when attempting to execute this in Java: after navigating to the page, trying to run:
JavascriptExecutor js = (JavascriptExecutor) driver;
String a = String.valueOf(js.executeScript("return let img = document.querySelector('.subscribe'), style = img.currentStyle || window.getComputedStyle(img, false), bi = style.backgroundImage.slice(4, -1).replace(/\"/g, \"\");"));
System.out.println(a)
An error is encountered: org.openqa.selenium.JavascriptException: javascript error: Unexpected identifier. Trying to add a 'return' statement before 'bi' results in a JS return statement error.
Please provide guidance on implementing this script, running it, and returning the execution result (URL as a string) from Java Selenium?