I'm using Selenium C# to test a pretty complex web UI in Internet Explorer 11. As you might know, Selenium's Click() tends to not work in which case inserting a JS click method is necessary. I'm running the dynamically generated script below using
(IJavaScriptExecutor) driver).ExecuteScript(script). Here is the script :
let iFrame = document.getElementById("dkwframe").contentWindow.document;
let element = iFrame.querySelector("[id*='_ImgLnkNewPage_LinkButtonControl']");
element.click();
The script works fine when I execute it directly in the IE console, but when executing with it Selenium I get this :
System.InvalidOperationException : Error executing JavaScript (UnexpectedJavaScriptError)
The IE console is empty so I don't think it's even trying. Also, switching browser isn't an option.
Thanks for the help
.click()you are no longer simulating a user click and no longer writing an end to end test. Theclickfrom Javascript simply executes the underlying listener or attached redirection which doesn't validate that a real user will be able to click the targeted element. Regarding you error,letis not supported by IE11 and should be replaced byvar.