Reputation: 1
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.
Upvotes: 0
Views: 4055
Reputation: 1
I got the same issue and solved using on error resume next statement
On error resume next
Set desc = description.Create
desc("micClass").value = "WebElement"
set WElementobj = browser("creationtime:=0").page("title:=.*").ChildObjects(desc)
msgbox welementobj.count
For i = 0 to welementobj.count-1
print welementobj(i).getroproperty("innertext")
Next
The reason this issue comes because of not all the objects would have innertext property.
Upvotes: 0
Reputation: 114835
There are several things wrong with your script
Set
objects since this is an objectFor
loop you should be looping on objects.count
not obj.count
For
body you should use objects(i).GetROProperty
(you forgot to index with i
)Print
statement you're indexing into childnames
for no reasonAfter 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
Upvotes: 1