2013-04-18 29 views
0

这发生在testcomplete版本9.20中,并针对firefox 19.0.2进行测试。在testcomplete中调用jquery时VBscript失败

第一个脚本文件称为test,它包含以下行:

'USEUNIT CommonFunctions 
Public Function test() 
    Call expandTree() 
End Function 

其他脚本文件被命名为CommonFunctions具有这样的功能:

Public Function expandTree() 
    Set foo = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").click() 
End Function 

当我运行脚本的自动化文件给出以下错误:

Microsoft VBscript runtime error. 

Object doesn't support this property or method:"contentDocument.Script.jQuery(...).Click'' 

Error location: 
Unit:"ContentSuite\Content\Script\CommonFunctions" 
Line:3972 Coloumn2 

如果将jquery放在同一个文件中,则不会发生同样的错误。也就是说,如果我运行这个它会正常工作,然后单击将很好地工作:

Public Function test() 
    Set foo = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").click() 
End Function 
+0

如果没有看到完整的代码,很难说。你能否编辑你的问题,并包含两个函数的代码? – Helen

+0

添加更多的细节,谢谢你的评论 – user2295001

+1

还没有足够的信息。请告诉我们TestComplete的版本以及您使用的浏览器。另外,如果直接从CommonFunctions单元运行,请检查是否可以执行expandTree例程。 –

回答

0

首先,当前的代码使用DOM click方法,它没有返回值,所以你需要删除Set foo =

错误可能是jQuery选择器没有找到任何匹配的对象。请尝试检查jQuery功能结果length属性:

Set links = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose") 
If links.length > 0 Then 
    links.click 
Else 
    Log.Error "Object not found." 
End If 

但其实没有必要在这里使用jQuery,因为TestComplete具有内置QuerySelector方法:

Set obj = Aliases.tree.QuerySelector("li[data-nodeid='sites'] a.openClose") 
If Not obj Is Nothing Then 
    obj.Click 
Else 
    Log.Error "Object not found." 
End If 
+0

感谢您的帮助helen!现在它工作正常,没有任何问题 – user2295001

0

我觉得现在的问题可能与您尝试调用jQuery方法返回的对象的方法单击的方法有关。由于此方法返回一个集合,因此请在单击它之前尝试获取特定对象:

Public Function expandTree() 
    Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").get(0).click() 
End Function