Hi All,
Greetings from Sri Lanka!
I need to attach an event listener to an element and later read a property of the target upon the event trigger. I thought of saving the result in a global variable until my script is ready to read the value. But the return is empty.
Web Page
Code
driver.switchTo().frame("iframeResult");
String SNIPPET_TO_GET_TARGET_VALUE = "var radio; document.querySelectorAll('[name=\"age\"]').forEach(elem => {elem.addEventListener('click',function(e){ radio = e.target.defaultValue})});";
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript(SNIPPET_TO_GET_TARGET_VALUE);
(String) executor.executeScript("return window.radio");
Environment
-Selenium 4.7.2
-Chrome v.108
-Java 1.9
Thanks,
Dumidu