如何单击Web表中可用的链接?

时间:2019-02-10 03:25:50

标签: vbscript qtp hp-uft uft14

Spy screenshot

我正在尝试单击链接,但是由于WebTable而无法执行。

所以我创建了我的函数库,这是链接的代码,我正在尝试调用它。我用名字fyi。

Call ClickLink ("sign-in") 



Sub ClickLink(LinkName)

 Set myPage=Browser("title:=.*").Page("title:=.*").Webtable()
 Set wLink = description.Create()  
    wLink("micClass").value="Link"  

    Set allLinks = myPage.ChildObjects(wLink) 
    TotalLinks = allLinks.count() 

    For Iterator = 0 To TotalLinks -1 
        If allLinks(i).GetRoproperty("name") = LinkName Then
            allLinks(i).click
            wait(3) 
            Exit For   

    ElseIf TotalLinks -1 Then 
        reporter.ReportEvent micFail, "Find Link", LinkName 
    End If  
    Next

    Set myPage = Nothing    
    Set wLink = Nothing 
    Set allLinks = Nothing


 End Sub

2 个答案:

答案 0 :(得分:1)

sel top 100 * from tablename; 不应以任何方式干扰标识链接,是什么使您认为链接确实如此?在UFT中,您可以省略DOM层次结构中的中间级别。

从屏幕快照中可以看到WebTable对象已经在对象存储库中,请尝试以简单的方式单击它。

Link

进一步阅读:Understanding the Web Test Object Model in HP Unified Functional Testing (UFT)

答案 1 :(得分:1)

您可以使用我不久前创建的此函数,它非常动态,因此可以接受任何存在的值

Function DARRTS_Click_Webelement_From_Webtable(clasVal,htmlidVal,Elementinnertext_To_Click,index)
On error resume next
Dim oDesc
'create description of the object
Set oDesc = Description.Create
oDesc.Add "MicClass","WebTable"
oDesc.Add "class",clasVal
oDesc.Add "html id",htmlidVal

If index <> "" Then
    oDesc.Add "index", index
End If

Element_innertxtVal = Elementinnertext_To_Click

i_RowCount = PageObj.Webtable(oDesc).RowCount

For rowNum = 1 to i_RowCount

    For ColNum = 1 to PageObj.Webtable(oDesc).ColumnCount(i_RowCount)

    set o_ElementObject = PageObj.Webtable(oDesc).childitem(rowNum,ColNum, "WebElement",0)

     s_ObjectName = o_ElementObject.GetROProperty("innertext")

    if s_ObjectName = s_ElementClassName then

    o_ElementObject.click

    'your passing report

    Else

    ' your failing report

    end if

    Next

Next
On error goto 0

'clean up
Set oDesc = nothing
Set o_ElementObject = nothing

结束功能

位置:

classVal- webtable对象的类值

index-如果有多个具有相同Text的链接,则为索引编号。如果不需要索引,则传递空白“”。

htmlidVal- webtable对象的类值

Elementinnertext_To_Click-您要从Web表格对象中单击的Web元素的内部文本