Unified Functional Testing Practitioners Forum

"For Each" error when runing in IE and FF

New Member.

"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.




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
     blnFound = True
     End If

  Set oAnchor = Nothing

   If blnFound = True Then Exit For

Next 'oAnchor

Set oAnchors = Nothing

End Function

Outstanding Contributor.

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




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
     blnFound = True
    End If

    If blnFound = True Then Exit For


Set oDesc = Nothing
Set links = Nothing

End Function


Let me know if this works for you.




“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”