executescript not working with InternetExplorer driver (Selenium)

jcd picture jcd · Dec 31, 2013 · Viewed 7.4k times · Source

For some reason, I cannot execute any javascript using "executescript" when I run my functional tests through IE. It works with Firefox. I have searched several hours on google with no luck.

I am simply calling

browser.driver.executeScript("console.log('test');")

or

JavascriptExecutor js = (JavascriptExecutor) driver
driver.executeScript("console.log('test');")

or whatever variation you please to call the executeScript method.

The stacktrace I am getting is:

org.openqa.selenium.WebDriverException: JavaScript error (WARNING:
The server did not provide any stacktrace information)
Command duration or timeout: 164 milliseconds
Build info: version: '2.37.1', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42',           
time: '2013-10-21 09:08:07'
System info: host: 'functionalTests', ip: '10.22.6.112', os.name: 'Windows 8', os.arch:    
'x86', os.version: '6.2', java.version: '1.6.0_45'
Session ID: 8b04c740-07a0-4678-a1b6-aacd56268625
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,     
enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false,   
browserName=internet explorer, enableElementCacheCleanup=true,   
unexpectedAlertBehaviour=dismiss, version=11, ie.usePerProcessProxy=false, 
cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false,  
initialBrowserUrl=http://localhost:17553/, handlesAlerts=true,  
ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, 
ie.browserCommandLineSwitches=, takesScreenshot=true}]
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at  
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at 
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:463)
at functional.utility.JQInstaller.installJQ(JQInstaller.groovy:16)
at functional.spec.NavigateAccountSettingsSpec.Navigate to the Account 
Settings(NavigateAccountSettingsSpec.groovy:39)

It is not a problem with my "JQInstaller" class, because I took that out and just tried console.log functions. It is a problem with this "executeScript" method. I am using Selenium 2.37.1.

Answer

Asyranok picture Asyranok · May 24, 2014

Have you tried the Enumerable version?

IJavaScriptExecutor js = WebDriver.driver as IJavaScriptExecutor;

if (js != null) {
     value = (string)js.ExecuteScript(javascriptArgumentAsString, element);
}