从Element获取父WebTable

Demo:

<table>

  <tr>

    <table border="1">

      <tr>

        <td>Attribute</td>

        <td>Value</td>

        <td>Description</td>

      </tr>

    </table>

    <table border="1">

      <tr>

        <td>left</td>

        <td>Alignment of the element</td>

      </tr>

    </table>

  </tr>

</table>

 

'Get the QTP WebTable from a specified object

Public Function GetWebTableFromElement(ByVal pObject)

Dim oTable, oParent

'Get the parent table, a DOM object

'Remember to include the Funtion GetParentOfElement!

Set oTable = GetParentofElement(pObject.Object, "TABLE")

'Get QTP test object parent of supplied object

Set oParent = pObject.GetTOProperty("parent")

If oTable is Nothing Then

Set GetWebTableFromElement = Nothing

Else

'Return the table using the source index
Set GetWebTableFromElement = oParent.WebTable("source_Index:=" & oTable.sourceIndex)

End If

End Function



'Funtion to get parent node on element

Function GetParentOfElement(ByVal pObject, ByVal pParentTagName)

On Error resume Next

'In case a QTP test object is passed, convert it
'to the DOM Object. This allows using the
'function on both DOM and QTP Test Objects
Set pObject = pObject.Object

Err.Clear

On Error Goto 0

'Search for object's parent node

Set oParent = pObject

'Search for the node with specified Tag Name

Do

Set oParent = oParent.parentNode

'if oParent == Nothing then we didn't find any parent object

'with the specified tag

Loop While Not(oParent is Nothing) And oParent.tagName <> pParentTagName

'Return the object found, else return Nothing if a tag is not found

Set GetParentofElement = oParent

End Function

 

How to use to find QTP table:

Set QTPTable = GetWebTableFromElement(Browser("name:=.*GetRowColumn.*")_

.WebElement("innertext:=Value"))

QTPTable.Highlight

 

How to register it:

RegisterUserFunc "<TargetWebObject>", "GetWebTableFromElement", "GetWebTableFromElement"

转载于:https://www.cnblogs.com/dushuai/articles/3433866.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值