TAGS :Viewed: 5 - Published at: a few seconds ago

[ General run error --2147467259 while using childobjects in QTP ]

I am trying to print the name of all the links present on a page. I have written the below code-->

SystemUtil.Run "Chrome.exe","www.timesofindia.com"
Dim obj, objects,objectnames,i
Set obj = Description.Create
obj("micclass").value = "Link"
objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj)
MsgBox Err.number
For i = 0 To obj.Count-1 Step 1
    childnames = objects.getROProperty("innertext")
    print childnames(i)
Next

I am getting general run error in line objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj)

The line MsgBox Err.number gives error number -2147467259

I tried to find out the cause with error number--2147467259 but didn't get any relevant answer. Please help.

Answer 1


There are several things wrong with your script

  • You need to Set objects since this is an object
  • In the For loop you should be looping on objects.count not obj.count
  • In the For body you should use objects(i).GetROProperty (you forgot to index with i)
  • In the Print statement you're indexing into childnames for no reason

After making these changes the script works for me but it's a bit slow, if you're still facing problems it may be that UFT times out while waiting for all the links to show up. If this is the case you can separate the query into several queries (for example where the innertext starts with each letter of the alphabet) and run them one after the other.

SystemUtil.Run "Chrome.exe","www.timesofindia.com"
Dim obj, objects,objectnames,i
Set obj = Description.Create
obj("micclass").value = "Link"
Set objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj)
If Err.Number <> 0 Then
    MsgBox "Error: " & Err.number   
End If

Print "Count " & objects.Count
For i = 0 To objects.Count-1 Step 1
    childnames = objects(i).getROProperty("innertext")
    print childnames
Next