【问题标题】:Accessing the properties of an Object that resides in another Object访问驻留在另一个对象中的对象的属性
【发布时间】:2015-09-11 13:47:38
【问题描述】:

我正在使用 UFT 和 VBS,并且我从返回其他对象的 JavaScript 命令中获取对象,但我无法访问这些对象的属性。

详细说明:

  1. 我在 UFT 中运行了一个命令,该命令返回 SlickGrid 表中的所有数据。命令为grid.getData();,并返回一个对象。
  2. 此对象设置为对象变量objListArray,层次结构为:
objListArray (Object)
      |
      |---0 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |        
      |---1 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |
      |---2 (Object)
      |        |
      |        |---Property1 : Value
      |        |---Property2 : Value
      |        |---Propertyx : Value
      |
      |---n (Object)
               |
               |---Property1 : Value
               |---Property2 : Value
               |---Propertyx : Value

无论我尝试什么,我都无法访问对象的属性。 有什么想法可以访问这些属性吗?我仅限于 VBS,因为这是 UFT 脚本。

到目前为止,我尝试了但没有成功:

objListArray(0).Property1   '--> Generic error

For Each x in objListArray  '--> Object does not support that

返回一般错误的各种其他组合。

【问题讨论】:

  • 你试过Set obj = objListArray(0)然后obj.Property1吗?
  • 确实我试过了......再次出现未知的运行时错误第 (24) 行:“设置 obj = objListArray(0)”。开始相信这无法通过 VBS 和 UFT 进行管理。
  • 你能检查一下数组函数是否还能正常工作吗?例如objListArray.shift().Property1?
  • objListArray 的实际类型是什么? (WScript.Echo TypeName(objListArray))
  • -Chris C:此功能可用且工作正常 -Ansgar Wiechers:类型 Object 是 JScriptTypeInfo 在找到仍然是 JavaScript 对象的类型后,我设法访问它。请在下面查看我的答案。

标签: javascript vbscript qtp hp-uft


【解决方案1】:

在 UFT 中访问 JavaScript 数组时出现问题,请参阅 my answer to another such question

我似乎记得 UFT 已经自己解决了问题,因此请尝试使用 .item,如果这不起作用,您可以尝试我上述答案中的建议。

【讨论】:

    【解决方案2】:

    我意识到该对象是 JScriptTypeInfo 类型

    为了访问它,我可以使用波纹管:

    objListArray.[0].Property1
    

    现在,要遍历 Object,您可以这样做:

    For i = 0 To objListArray.Length-1
        x =  eval("objListArray.[" & index & "].[Account Number]")
        'Do anything you want with x
    Next
    

    【讨论】:

      【解决方案3】:

      我认为它可能是字典对象的集合(字典中的字典)。

      尝试通过这种方式访问​​。

      objListArray(0)("Property1")

      或者

      objListArray(0).Item("Property1")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-26
        • 2017-08-02
        相关资源
        最近更新 更多