51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3127|回复: 1
打印 上一主题 下一主题

求助!webdriver 执行js异常,急!

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2014-5-14 10:00:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
代码:
  1.                 JavascriptExecutor jse =(JavascriptExecutor)driver;
  2.                 StringBuilder strBuilder =new StringBuilder();
  3.                 strBuilder.append("var xmlhttp; var msg=\"不存在\"; ");
  4.                 strBuilder.append("if(window.ActiveXObject){");
  5.                 strBuilder.append("xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}");
  6.                 strBuilder.append("else if(window.XMLHTTPRequest){");
  7.                 strBuilder.append("xmlhttp = new XMLHTTPRequest();}");
  8.                 strBuilder.append("if(xmlhttp==null){msg=\"nothing\"}");
  9.                 strBuilder.append("xmlhttp.open(\"GET\",\""+url+"\",false);");
  10.                 strBuilder.append("xmlhttp.send(null);");
  11.                 strBuilder.append("if(xmlhttp.readyState==4)");
  12.                 strBuilder.append(" msg= ((xmlhttp.Status==200)?\"存在\":\"不存在\");");
  13.                 strBuilder.append("return msg;");
  14.                 System.out.println("strBuilder.toString():"+strBuilder.toString());
  15.                 String msg= jse.executeScript(strBuilder.toString()).toString();
  16.                 System.out.println("msg:"+msg);
复制代码
异常信息:
  1. Started InternetExplorerDriver server (32-bit)
  2. 2.35.3.0
  3. Listening on port 47166
  4. 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
  5. 2014-05-14 09:43:21 [Forwarding newSession on session null to remote]-[INFO] Retrying request
  6. 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;
  7. Exception in thread "main" org.openqa.selenium.WebDriverException: JavaScript error (WARNING: The server did not provide any stacktrace information)
  8. Command duration or timeout: 209 milliseconds
  9. Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32'
  10. 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'
  11. Session ID: bb510bbb-b70c-4ff2-8816-6f0a1757796e
  12. Driver info: org.openqa.selenium.ie.InternetExplorerDriver
  13. 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}]
  14.         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  15.         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  16.         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  17.         at java.lang.reflect.Constructor.newInstance(Unknown Source)
  18.         at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
  19.         at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
  20.         at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
  21.         at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
复制代码
经过调试发现是:strBuilder.append("xmlhttp.open(\"GET\",\""+url+"\",false);");运行到该行时发生异常


BTW,吐槽51上面发个帖子真难!不知道诸位大仙怎么受得了!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2014-5-14 10:18:06 | 只看该作者
自己顶下吧
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-23 04:03 , Processed in 0.067746 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表