本文介绍了HP QTP 11:在Firefox中运行时脚本执行失败,但调试查看器显示操作结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图在Firefox 3.6上运行我们为IE编写的自动化,面对那些令人沮丧的问题:我有一个代码: 设置cellDataItems = Browser()。Page()。WebElement()。Object.getElementsByTagName(div)对于i = 0到cellDataItems.length -1 MsgBox (cellDataItems.item(i).innerHTML)下一页 MsgBox if stops with error:然后我按debug,看到i = 0。我添加cellDataItems.item(i).innerHTML到调试查看器,它显示它的值(见下文)没有错误。 当i = 0时,cellDataItems.item(i).innerHTML的值为: p> < table class =x-grid3-row-tablestyle =width:100px; border =0cellpadding =0cellspacing =0>< tbody>< tr>< td class =x-grid3-col x-grid3-cell x-grid3-td- grid3-cell-firststyle =width:98px; text-align:left; tabindex =0>< div class =x-grid3-cell-inner x-grid3-col-0unselectable =on>< div align =left> AUD / USD< div>< / div>< / td>< / tr>< / tbody>< / table& 因此,为什么脚本会失败并显示错误, 谢谢! 更新在Firefox的控制台中,我会看到更多详细信息: 更新2: MsgBox(eval(cellDataItems.item(i).innerHTML)) - 有用!也许有一些方法可以做firefox的QTP扩展的调试代码? update 3: 如何可能:expression colItem.className的值为x-panel,但是在执行表达式之后 sClassName = colItem.className sClassName的值为空: 这样工作: sClassName = eval colItem.className) 这怎么可能?!!!!!!或者我变得疯了,或者QTP 11里面有一个biiig缺陷!解决方案我发现原因, / p> 所以,在关联库中的某处有一个代码: itemCol = windows.item(i)'line 1 sClassName = itemCol.className'line 2 另一个库中有一个表达式: arrMyTradeInfo = GlobalDictionary.Item(gdTrades) 在执行第1行时,QTP会产生错误: TypeError:obj [FuncName]未定义但是如果我将代码更改为(注意item函数名 - 它在小写字母) - 行1将工作! !: arrMyTradeInfo = GlobalDictionary.item(gdTrades) 但是它不会在第2行工作 - 参见问题本身的更新3 - sClassName的值将为空,但是itemCol.className可以包含字符串。在另一个库中,我有一个函数(通知className参数): 函数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)结束如果结束函数 我改变它的名字到不同的东西(例如csName),行2是工作的。 函数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)结束如果结束函数 b $ b 所以,这是解决方法。我不能解释为什么这是发生,我的猜测是:VBScript不是严格类型。在QTP中,它们实现了类似于虚拟函数调用的功能,如在C ++和Java中基于某种运行时类型信息,但对于来自Firefox的DOM对象存在一些冲突,他们以错误的方式收集了RTTI。 所以,主要的结论和关注:只有一个错误的letter-case(Item而不是item)可能打破你的代码,使用firefox的dom,并将给你许多愉快的时间 将在惠普支持下打开票证。 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)NextWhen script goes to line with MsgBox if stops with error: 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: 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.classNamethe 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! 解决方案 I found the reason and found workaround.So, somewhere in associated library I has a code:Set itemCol = windows.item(i) ' line 1sClassName = itemCol.className ' line 2And in another library I have an expression :arrMyTradeInfo=GlobalDictionary.Item("gdTrades")With this code during execution of line 1 QTP will give error: 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 FunctionWhen 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 FunctionSo, 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. 这篇关于HP QTP 11:在Firefox中运行时脚本执行失败,但调试查看器显示操作结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 09:38