selenium.getEval()和(JavascriptExecutor)驱动程序失败,SeleniumException等待Firefox 17/19中的evaluate.js(webdriver v2.32.0)

时间:2013-09-09 20:39:22

标签: firefox selenium selenium-webdriver

当我尝试在firefox 17.0中执行JS代码时,我得到以下异常。 v2.32更改日志提到它支持10esr, 17esr, 19, 20。而且我也知道最新的webdriver版本是2.35但是由于某些测试的定位器问题,我正在使用v2.32。这适用于chrome v29

有关如何修复它的任何想法?提前谢谢

以下是代码:

public void commonWaitForAjax() throws Exception {
        for (int i=1; i<100; i++) {
      //    String status = selenium.getEval("$.active");   // fails here (legacy selenium method)
            String jsCode = "$.active";
            JavascriptExecutor js = (JavascriptExecutor) driver;
            printComment("executing: "+ jsCode);
            String status = (String) js.executeScript(jsCode); // fails here too (webdriver method)
            printComment("status: " + status);
            if( Integer.valueOf(status) == 0) {
                printComment("Ajax complete!!!");
                break;
            } else {
                printComment("Waiting for Ajax to complete...");
                Thread.sleep(1000);
            }
        }
    }

这是在控制台中记录的:

Sep 09, 2013 1:32:32 PM org.openqa.selenium.internal.seleniumemulation.WaitForPageToLoad handleSeleneseCommand
WARNING: Cannot determine whether page supports ready state. Abandoning wait.

异常

testMetersOverview(marklogic.test.MetersOverview)
com.thoughtworks.selenium.SeleniumException: waiting for evaluate.js load failed
Command duration or timeout: 10.26 seconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 5399e6a6-8134-4c08-b6d2-13716b8b96e2
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=23.0.1}]
    at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:44)
    at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:40)
    at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:140)
    at org.openqa.selenium.WebDriverCommandProcessor.getString(WebDriverCommandProcessor.java:111)
    at com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:479)
    at marklogic2.Common.commonWaitForAjax(Common.java:1172)
    at marklogic.test.MetersOverview.testMetersOverview(MetersOverview.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
    at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
    at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
    at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
Caused by: org.openqa.selenium.WebDriverException: waiting for evaluate.js load failed
Command duration or timeout: 10.26 seconds
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Session ID: 5399e6a6-8134-4c08-b6d2-13716b8b96e2
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=23.0.1}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    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 org.openqa.selenium.internal.seleniumemulation.GetEval.handleSeleneseCommand(GetEval.java:39)
    at org.openqa.selenium.internal.seleniumemulation.GetEval.handleSeleneseCommand(GetEval.java:1)
    at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:35)
    ... 39 more
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: waiting for evaluate.js load failed
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
Driver info: driver.version: unknown
    at <anonymous class>.r(file:///C:/Users/sreddy/AppData/Local/Temp/anonymous7980890323570416361webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8321)
    at <anonymous class>.fxdriver.Timer.prototype.runWhenTrue/g(file:///C:/Users/sreddy/AppData/Local/Temp/anonymous7980890323570416361webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:392)
    at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/sreddy/AppData/Local/Temp/anonymous7980890323570416361webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:386)

FAILURES!!!
Tests run: 1,  Failures: 1

1 个答案:

答案 0 :(得分:0)

你必须在正在执行的JS脚本中做一个返回,如下所示:

String status = (String) js.executeScript("return STARTED");