最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - executescript not working with InternetExplorer driver (Selenium) - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Dec 31, 2013 at 18:17 jcdjcd 2315 silver badges15 bronze badges 11
  • 2 What version of IE are you using? IE8 and below do not have console.log – Paul Harris Commented Dec 31, 2013 at 19:43
  • I am using 9,10, and 11 – jcd Commented Jan 2, 2014 at 16:30
  • 1 @elgalu, We have no missing resources on that page. Bummer, I was hoping that would be it. – jcd Commented Jan 25, 2014 at 0:50
  • 1 I have the same issue, using Selenium 2.40.0, I reported it: code.google./p/selenium/issues/… – Fried Hoeben Commented Mar 27, 2014 at 13:26
  • 1 You say "nothing works," but your example will error if the F12 Developer Tools window is not open (accessing "console.<anything>" if the F12 tools aren't open throws an error in at least IE < 10). What happens if you do something like js.executeScript("return 1+1;");? – JimEvans Commented Mar 27, 2014 at 18:27
 |  Show 6 more ments

2 Answers 2

Reset to default 1

Have you tried the Enumerable version?

IJavaScriptExecutor js = WebDriver.driver as IJavaScriptExecutor;

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

IE 7 and below do not have console.log.

IE 8, 9 and 10 have it but dev tools must be open. Open these with F12.

IE 11 works fine.

Each IE browser has a script debug window which can be activated in IE tools menu. This would have caused an alert to show you the reason for failure in older IE browsers.

If you want extra help understanding this look here: Specifically at Walter's answer for an excellent solution

发布评论

评论列表(0)

  1. 暂无评论