HP QTP 11:在 Firefox 中运行时脚本执行失败,但调试查看器显示操作结果
我正在尝试在 Firefox 3.6 上运行为 IE 编写的自动化,并面临这些令人沮丧的问题: 我有一个代码:
Set cellDataItems = Browser().Page().WebElement().Object.getElementsByTagName("div")
For i = 0 to cellDataItems.length -1
MsgBox (cellDataItems.item(i).innerHTML)
Next
当脚本与 MsgBox 一致时,如果停止并出现错误:
类型错误:obj[FuncName] 未定义
然后我按 debug,看到 i=0。我将 cellDataItems.item(i).innerHTML 添加到调试查看器中,它显示了它的值(见下文),没有错误。此外,cellDataItems.item(i).textContent 在调试查看器中显示良好。
当 i=0 时,cellDataItems.item(i).innerHTML 的值是:
<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>
那么,为什么脚本会因该错误而失败,但调试查看器会显示它? 谢谢你!
更新 在 Firefox 的控制台中我看到更多详细信息:
错误:obj[FuncName] 未定义源文件: 文件:///C:/Program%20Files/HP/QuickTest%20Professional/Bin/Mozilla/Common/components/ScriptWrapperXPCOM.js -> 文件:///c:/program%20files/hp/quicktest%20professional/bin/JSFiles/mzDotObj.js 线路:76
更新 2:
MsgBox (eval(cellDataItems.item(i).innerHTML))
当我使用 eval 时 - 它有效!也许有某种方法可以调试 QTP 的 Firefox 扩展代码?
更新3: 这怎么可能:表达式“colItem.className”的值为“x-panel”,但在执行表达式后,
sClassName = colItem.className
sClassName 的值为空:
这有效: sClassName = eval("colItem.className")
这怎么可能?!!!!!!或者我快疯了,或者QTP 11内部有一个很大的缺陷!
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:
This works:
sClassName = eval("colItem.className")
How this even possible?!!!!!! Or I'm getting crazy, or QTP 11 has a biiig defect inside!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了原因并找到了解决方法。
因此,在关联库中的某处我有一个代码:
在另一个库中我有一个表达式:
在执行第 1 行期间使用此代码 QTP 将给出错误:
但它不会在第 2 行中起作用 - 请参阅问题本身中的更新 3 - sClassName 的值为空,但 itemCol.className 可以包含字符串。在另一个库中,我有一个函数(注意 className 参数):
当我将其名称更改为不同的名称(例如 csName)时,第 2 行正在工作!
所以,这是解决方法。我无法解释为什么会发生这种情况,我的猜测是:VBScript 不是严格类型的。在 QTP 中,他们基于某种运行时类型信息实现了类似于 C++ 和 Java 中的“虚拟函数调用”之类的东西,但是对于 Firefox 中的 DOM 对象,存在一些冲突,他们以错误的方式收集 RTTI。
因此,主要结论和关注点是:只有一个错误的字母大小写(Item 而不是 item)可能会破坏您的代码,该代码与 Firefox 的 dom 一起工作,并且会给您带来许多愉快的调试时间!所以,小心!
将在 HP 支持下开票。
I found the reason and found workaround.
So, somewhere in associated library I has a code:
And in another library I have an expression :
With this code during execution of line 1 QTP will give error:
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):
When I changed it name to something different (csName for example), line 2 is working!!!
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.