Attempting to initiate a JavaScript 'change' event on an element within an iframe. The following is the code snippet I have been using:
// accessing the iframe window
var iframeDoc = document.getElementsByTagName("iframe")[0].contentWindow.document;
// selecting the target element
var targetElement = iframeDoc.querySelector("#some_id");
// adding a listener to the target element to ensure the event is triggered
targetElement.addEventListener("onchange", function(){console.log("change event triggered");});
// setting a value in the target element
targetElement.value = "abc";
// creating a custom event
var customEvent = iframeDoc.createEvent("HTMLEvents");
customEvent.intEvent("change", false, true);
// triggering the event on the element
targetElement.dispatchEvent(customEvent)
// clicking on the save button
No errors are appearing after the final line execution and the console displays the message. However, the value provided by selenium does not persist upon clicking the Save
button in the form.
Technology stack: Java, IE 11, selenium 3.141.59 Native Events Disabled