QTP error:Object Required:”WScript”

技术流评论7,133阅读模式

在QTP执行中,有这样一个有趣的问题,下列代码:

Set WshShell=Wscript.CreateObject("WScript.Shell")
WshShell.Run "notepad"文章源自原紫番博客-https://www.yuanzifan.com/1712.html

将此段代码保存与txt中,再重命名为*.vbs是可以正常执行的,打开一个记事本程序。文章源自原紫番博客-https://www.yuanzifan.com/1712.html

但是放在QTP中,就无法正常执行,报错为:Object Required:"Wcript"文章源自原紫番博客-https://www.yuanzifan.com/1712.html

解决方案:只要将Wcript去掉就可以了:Set WshShell=Wscript.CreateObject("WScript.Shell")
WshShell.Run "notepad"文章源自原紫番博客-https://www.yuanzifan.com/1712.html

因为WScript 对象,提供对 Windows 脚本宿主对象模型根对象的访问。这个对象在Windows下可以直接执行,但是在QTP中,是通过QTP再访问Windows,因此QTP无法识别这个未经定义的对象,导致此类错误。文章源自原紫番博客-https://www.yuanzifan.com/1712.html 文章源自原紫番博客-https://www.yuanzifan.com/1712.html

 最后更新:2012-4-26

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证