简体   繁体   English

executioncript不能与InternetExplorer驱动程序(Selenium)一起使用

[英]executescript not working with InternetExplorer driver (Selenium)

For some reason, I cannot execute any javascript using "executescript" when I run my functional tests through IE. 出于某种原因,当我通过IE运行我的功能测试时,我无法使用“executioncript”执行任何javascript。 It works with Firefox. 它适用于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. 或者您可以调用executeScript方法的任何变体。

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. 这对我的“JQInstaller”类来说不是问题,因为我把它拿出来并尝试了console.log函数。 It is a problem with this "executeScript" method. 这是“executeScript”方法的一个问题。 I am using Selenium 2.37.1. 我正在使用Selenium 2.37.1。

Have you tried the Enumerable version? 你试过Enumerable版本吗?

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 7及更低版本没有console.log。

IE 8, 9 and 10 have it but dev tools must be open. IE 8,9和10有它,但开发工具必须是开放的。 Open these with F12. 用F12打开它们。

IE 11 works fine. IE 11工作正常。

Each IE browser has a script debug window which can be activated in IE tools menu. 每个IE浏览器都有一个脚本调试窗口,可以在IE工具菜单中激活。 This would have caused an alert to show you the reason for failure in older IE browsers. 这会导致警报显示旧IE浏览器失败的原因。

If you want extra help understanding this look here: Specifically at Walter's answer for an excellent solution 如果您需要额外的帮助,请在此处了解这一点: 特别是Walter对优秀解决方案的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery DateTimePicker在InternetExplorer中不起作用 - JQuery DateTimePicker not working in InternetExplorer selenium executeScript在IE上挂起 - selenium executeScript hangs on IE 如何使用Selenium Java Web驱动程序的executeScript方法执行用户定义的JavaScript函数 - How to execute a user defined JavaScript function using executeScript method of Selenium Java web driver Chrome executeScript函数不起作用 - Chrome executeScript function not working IE驱动程序无法使用Internet Explorer驱动程序配置在JMeter中使用Selenium - IE driver is not working with Selenium in JMeter using Internet explorer driver config 滚动执行脚本的量角器不工作 - Protractor scrolling through executeScript not working 如何使用Selenium ExecuteScript函数获取HashTable - How to get HashTable with Selenium ExecuteScript function Selenium&webdriver.io如何使用executeScript? - Selenium & webdriver.io how to use executeScript? Chrome扩展程序:chrome.tabs.executeScript无效 - Chrome Extension: chrome.tabs.executeScript not working Selenium Web 驱动程序的文件上传功能无法通过 sendkeys 工作 - File Upload functionality of Selenium web driver not working through sendkeys
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM