Question

This occurs in testcomplete version 9.20, and test against firefox 19.0.2.

First script file is called test and it contains the following lines:

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

The other script file is named CommonFunctions has this function:

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

When I run the script the automation files giving the following error:

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

The same error will not occur if I place the jquery in the same file. That is if I run this it will work properly, and the click would work fine:

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

Solution

First of all, your current code uses the DOM click method, which does not have a return value, so you need to remove Set foo =.

The error might be that the jQuery selector did not find any matching objects. Try checking the length property of the jQuery function result:

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

But actually there's no need to use jQuery here, since TestComplete has the built-in QuerySelector method:

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

OTHER TIPS

I think that the problem can be related to the fact that you are trying to call the click method of an object returned by the jQuery method. Since this method returns a collection, try getting a specific object before clicking it:

Public Function expandTree()
  Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").get(0).click()
End Function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top