While testing in Chrome's developer tools console, I successfully executed the following codes. However, when attempting to run them in Selenium, an error stating "missing ) after argument list" was encountered. This issue suggests incorrect syntax, but the reason behind it remains unclear. It is important to note that each attempt was conducted independently.
//Modified Attempt 1
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript( "var evt = document.createEvent('MouseEvent');" +
"evt.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 382, 290 , false, false, false, false, 0, null);" +
"var cb = document.getElementById('gameCanvas');"+
"cb.dispatchEvent(evt);"+
"setTimeout(function(){"+
"evt.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 382, 290 false, false, false, false, 0, null);"+
"cb.dispatchEvent(evt);}, 100); };");
//Revised Attempt 2
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript( "var evt = document.createEvent('MouseEvent');" +
"evt.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 382, 290 , false, false, false, false, 0, null);" +
"var cb = document.getElementById('gameCanvas');"+
"cb.dispatchEvent(evt);"+
"evt.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 382, 290 false, false, false, false, 0, null);"+
"cb.dispatchEvent(evt);");