|
代码:- JavascriptExecutor jse =(JavascriptExecutor)driver;
- StringBuilder strBuilder =new StringBuilder();
- strBuilder.append("var xmlhttp; var msg=\"不存在\"; ");
- strBuilder.append("if(window.ActiveXObject){");
- strBuilder.append("xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}");
- strBuilder.append("else if(window.XMLHTTPRequest){");
- strBuilder.append("xmlhttp = new XMLHTTPRequest();}");
- strBuilder.append("if(xmlhttp==null){msg=\"nothing\"}");
- strBuilder.append("xmlhttp.open(\"GET\",\""+url+"\",false);");
- strBuilder.append("xmlhttp.send(null);");
- strBuilder.append("if(xmlhttp.readyState==4)");
- strBuilder.append(" msg= ((xmlhttp.Status==200)?\"存在\":\"不存在\");");
- strBuilder.append("return msg;");
- System.out.println("strBuilder.toString():"+strBuilder.toString());
- String msg= jse.executeScript(strBuilder.toString()).toString();
- System.out.println("msg:"+msg);
复制代码 异常信息:- Started InternetExplorerDriver server (32-bit)
- 2.35.3.0
- Listening on port 47166
- 2014-05-14 09:43:21 [Forwarding newSession on session null to remote]-[INFO] I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
- 2014-05-14 09:43:21 [Forwarding newSession on session null to remote]-[INFO] Retrying request
- strBuilder.toString():var xmlhttp; var msg="不存在"; if(window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}else if(window.XMLHTTPRequest){xmlhttp = new XMLHTTPRequest();}if(xmlhttp==null){msg="nothing"}xmlhttp.open("GET","http://www.baidu.com",false);xmlhttp.send(null);return msg;
- Exception in thread "main" org.openqa.selenium.WebDriverException: JavaScript error (WARNING: The server did not provide any stacktrace information)
- Command duration or timeout: 209 milliseconds
- Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
- System info: host: 'lap0099', ip: '172.27.35.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'
- Session ID: bb510bbb-b70c-4ff2-8816-6f0a1757796e
- Driver info: org.openqa.selenium.ie.InternetExplorerDriver
- Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, ignoreZoomSetting=false, enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=6, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, ignoreProtectedModeSettings=true, requireWindowFocus=false, handlesAlerts=true, initialBrowserUrl=http://localhost:47166/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}]
- 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:193)
- at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
- at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
- at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
复制代码 经过调试发现是:strBuilder.append("xmlhttp.open(\"GET\",\""+url+"\",false);");运行到该行时发生异常
BTW,吐槽51上面发个帖子真难!不知道诸位大仙怎么受得了! |
|