3

I'm trying to run our automation, written for IE, on Firefox 3.6 and facing those frustrating problem: I have a code:

Set cellDataItems = Browser().Page().WebElement().Object.getElementsByTagName("div")
For i = 0 to cellDataItems.length -1 
    MsgBox (cellDataItems.item(i).innerHTML)
Next

When script goes to line with MsgBox if stops with error:

TypeError: obj[FuncName] is undefined

Then I press debug, see that i=0. I added cellDataItems.item(i).innerHTML into debug viewer, it shows it's value (see below) without errors. Also, cellDataItems.item(i).textContent shows fine in Debug Viewer.

The value of cellDataItems.item(i).innerHTML when i=0 is:

<table class="x-grid3-row-table" style="width: 100px;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="x-grid3-col x-grid3-cell x-grid3-td-0 x-grid3-cell-first " style="width: 98px; text-align: left;" tabindex="0"><div class="x-grid3-cell-inner x-grid3-col-0" unselectable="on"><div align="left">AUD/USD</div></div></td></tr></tbody></table>

So, why script fails with that error, but debug viewer shows it? Thank you!

Update In Firefox's Console I see more details:

Error: obj[FuncName] is undefined Source File: file:///C:/Program%20Files/HP/QuickTest%20Professional/Bin/Mozilla/Common/components/ScriptWrapperXPCOM.js -> file:///c:/program%20files/hp/quicktest%20professional/bin/JSFiles/mzDotObj.js Line: 76

update 2:

MsgBox (eval(cellDataItems.item(i).innerHTML)) 

When I use eval - it works! Maybe is there a some way do debug code of QTP's extension for firefox?

update 3: How is that possible: expression "colItem.className" has value "x-panel", but after I execute expression

sClassName = colItem.className

the value of sClassName is Empty: line 570 was executed, but sclassName is still empty

This works: sClassName = eval("colItem.className")

How this even possible?!!!!!! Or I'm getting crazy, or QTP 11 has a biiig defect inside!

Motti
  • 110,860
  • 49
  • 189
  • 262
vmg
  • 9,920
  • 13
  • 61
  • 90
  • 2
    This does indeed look like a defect in QTP 11 (more specifically in the patch for Firefox3.6 support). I would recommend opening a ticket with HP support. – Motti Sep 07 '11 at 05:34
  • Thank you for help! You may look at my investigations below. – vmg Sep 07 '11 at 10:15

1 Answers1

0

I found the reason and found workaround.

So, somewhere in associated library I has a code:

Set itemCol = windows.item(i) ' line 1
sClassName = itemCol.className ' line 2

And in another library I have an expression :

arrMyTradeInfo=GlobalDictionary.Item("gdTrades")

With this code during execution of line 1 QTP will give error:

TypeError: obj[FuncName] is undefined But if I change code to (notice "item" function name - it in lower-case now) - the line 1 will work!!!:

arrMyTradeInfo=GlobalDictionary.item("gdTrades")

But then it will not work in line 2 - see update 3 in the question itself - the value of sClassName will be empty, but itemCol.className could contain string. In another library I have a function (notice className parameter):

Function GetFirstObjectByClassName(byVal Parent, byVal className, byVal tag)
    Dim result
     result = getElementsByClassName(Parent, className, tag)
     If (UBound(result)<0) Then
        set GetFirstObjectByClassName = Nothing
    Else
        set GetFirstObjectByClassName = result (0)
    End If   
End Function

When I changed it name to something different (csName for example), line 2 is working!!!

Function GetFirstObjectByClassName(byVal Parent, byVal csName, byVal tag)
    Dim result
     result = getElementsByClassName(Parent ,csName, tag)
     If (UBound(result)<0) Then
        set GetFirstObjectByClassName = Nothing
    Else
        set GetFirstObjectByClassName = result (0)
    End If   
End Function

So, this is workaround. I can't explain it why is this happening, my guess is: VBScript is not strictly-typed. And in QTP they implemented something like "virtual functions calls" like in C++ and Java based on some kind of run-time type information, butfor DOM objects from Firefox there was some collision, they gathered RTTI in wrong way.

So, the main conclusion and concern: only one wrong letter-case (Item instead of item) could broke your code, that work with firefox's dom and will give you many pleasant hours of debugging! SO, be careful!

Will open ticket with HP support.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
vmg
  • 9,920
  • 13
  • 61
  • 90