【问题标题】:General run error --2147467259 while using childobjects in QTP在 QTP 中使用子对象时出现一般运行错误 --2147467259
【发布时间】:2015-08-01 06:20:02
【问题描述】:

我正在尝试打印页面上所有链接的名称。我写了下面的代码-->

SystemUtil.Run "Chrome.exe","www.timesofindia.com"
Dim obj, objects,objectnames,i
Set obj = Description.Create
obj("micclass").value = "Link"
objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj)
MsgBox Err.number
For i = 0 To obj.Count-1 Step 1
    childnames = objects.getROProperty("innertext")
    print childnames(i)
Next

我在objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj) 行中遇到一般运行错误

MsgBox Err.number 行给出错误号-2147467259

我试图通过错误号--2147467259 找出原因,但没有得到任何相关答案。请帮忙。

【问题讨论】:

    标签: qtp child-objects


    【解决方案1】:

    你的脚本有几个问题

    • 你需要Set对象,因为这是一个对象
    • For 循环中,您应该循环objects.count 而不是obj.count
    • For 正文中,您应该使用objects(i).GetROProperty(您忘记使用i 进行索引)
    • Print 语句中,您无缘无故地索引到 childnames

    进行这些更改后,脚本对我有效,但它有点慢,如果您仍然遇到问题,可能是 UFT 在等待所有链接显示时超时。如果是这种情况,您可以将查询分成几个查询(例如,innertext 以字母表中的每个字母开头)并一个接一个地运行。

    SystemUtil.Run "Chrome.exe","www.timesofindia.com"
    Dim obj, objects,objectnames,i
    Set obj = Description.Create
    obj("micclass").value = "Link"
    Set objects = Browser("micclass:=browser").Page("micclass:=Page").ChildObjects(obj)
    If Err.Number <> 0 Then
        MsgBox "Error: " & Err.number   
    End If
    
    Print "Count " & objects.Count
    For i = 0 To objects.Count-1 Step 1
        childnames = objects(i).getROProperty("innertext")
        print childnames
    Next
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题并使用 on error resume next 语句解决了

      On error resume next
      Set desc = description.Create
      desc("micClass").value = "WebElement"
      set WElementobj = browser("creationtime:=0").page("title:=.*").ChildObjects(desc)
      msgbox welementobj.count
      For i = 0 to welementobj.count-1
          print welementobj(i).getroproperty("innertext")
      Next
      

      出现此问题的原因是并非所有对象都具有内部文本属性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-19
        • 1970-01-01
        • 1970-01-01
        • 2019-01-03
        • 1970-01-01
        • 2016-07-21
        • 2018-06-21
        相关资源
        最近更新 更多