Re: "For Each" error when runing in IE and FF (68 Views)
Reply
Occasional Visitor
manix3
Posts: 1
Registered: ‎11-18-2013
Message 1 of 2 (94 Views)

"For Each" error when runing in IE and FF

Hello All,

 

I created a function that I use to click a link on a web application web page. When I run the function using IE it works but when I run it on FF I get an error message stating: that this object does not support this property or method.

 

Here is my code: All help would greatly be appreciated.

 

Thanks

 

Public Function ClickLink(BName,PName,LinkText)

Dim oAnchors
Dim oAnchor
Dim blnFound

'This will grab all of the links in the page.
Set oAnchors = Browser(BName).Page(PName).Object.GetElementsByTagName("A") 


blnFound = False
For Each oAnchor in oAnchors <-Here is where I get the error in FF


  'Use some property to identify which link you are on  'And if it's the right one


  If oAnchor.innertext = LinkText Then
     oAnchor.Click()
     blnFound = True
     End If


  Set oAnchor = Nothing

   If blnFound = True Then Exit For

Next 'oAnchor

Set oAnchors = Nothing

End Function

Please use plain text.
HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 2 of 2 (68 Views)

Re: "For Each" error when runing in IE and FF

 

Hello,

 

If you still need assistance, please check following known limitation when working with Firefox, which I suspect of being the cause of the problem:

(from following article: http://support.openview.hp.com/selfsolve/document/KM1338856)

The Object property accesses DOM objects

The DOM structure/architecture used on Internet Explorer is not the same as one used by FireFox, so when creating scripts involving DOM statements, logic dedicated for each environment must be implemented. For more information on each DOM, see:

As a workaround, I would suggest you use a Description object as follows:

 

Public Function ClickLink(BName,PName,LinkText)

Set oDesc = Description.Create
oDesc("micclass").Value = "Link"
Set links = Browser(BName).Page(PName).ChildObjects(oDesc)

blnFound = False

For i=0 To links.Count - 1
  
    If links.Item(i).GetROProperty("innertext")= LinkText Then
     links.Item(I).Click()
     blnFound = True
    End If


    If blnFound = True Then Exit For

Next 

Set oDesc = Nothing
Set links = Nothing

End Function

 

Let me know if this works for you.

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation