在testcomplete中调用jquery时VBscript失败

在testcomplete中调用jquery时VBscript失败,jquery,vbscript,testcomplete,Jquery,Vbscript,Testcomplete,这发生在testcomplete 9.20版和针对firefox 19.0.2的测试中 第一个脚本文件称为test,它包含以下行: 'USEUNIT CommonFunctions Public Function test() Call expandTree() End Function 另一个脚本文件名为CommonFunctions具有以下功能: Public Function expandTree() Set foo = Aliases.tree.contentDocument.

这发生在testcomplete 9.20版和针对firefox 19.0.2的测试中

第一个脚本文件称为
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

首先,当前代码使用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具有内置方法:


我认为问题可能与您试图调用jQuery方法返回的对象的click方法有关。由于此方法返回集合,请在单击特定对象之前尝试获取该对象:

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

很难说没有看到完整的代码。请您编辑您的问题并包含两个函数的代码,好吗?添加了更多详细信息,谢谢您的评论。信息仍然不够。请告诉我们您使用的是哪个版本的TestComplete和哪个浏览器。另外,如果您直接从CommonFunctions单元运行expandTree例程,请检查它是否可以执行。我使用的是testcomplete 9.20版,我在firefox 19.0.2上尝试过这一点。如果直接从通用函数单元调用展开例程,则效果良好。谢谢您的帮助!现在它工作正常,没有任何问题
Public Function expandTree()
  Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").get(0).click()
End Function