出于某种原因,当我通过 IE 运行我的功能测试时,我无法使用“executescript”执行任何 javascript。它适用于 Firefox。我在谷歌上搜索了几个小时但没有运气。
我只是打电话
browser.driver.executeScript("console.log('test');")
或者
JavascriptExecutor js = (JavascriptExecutor) driver
driver.executeScript("console.log('test');")
或任何您喜欢调用 executeScript 方法的变体。
我得到的堆栈跟踪是:
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)
我的“JQInstaller”类不是问题,因为我把它去掉了,只是尝试了 console.log 函数。这个“executeScript”方法有问题。我正在使用 Selenium 2.37.1。
最佳答案
您是否尝试过 Enumerable 版本?
IJavaScriptExecutor js = WebDriver.driver as IJavaScriptExecutor;
if (js != null) {
value = (string)js.ExecuteScript(javascriptArgumentAsString, element);
}