简体   繁体   English

QTP UFT- Web元素行计数

[英]QTP UFT- Web Element Row Count

I want to find the row count for this below. 我想在下面找到这个行数。 I tried to use this by using HTML TAG = A by below code 我尝试通过下面的代码使用HTML TAG = A来使用它

Set oDesc = Description.Create()
oDesc("micclass").Value = "WebElement"
Set Elements = Browser("creationtime:=0").Page("index:=1").Object.GetElementsByTagName("a")
Msgbox "Total links: " & Elements.Length

I am getting wrong row count because few of those web elements has different html tag 'DIV'. 我得错了行数,因为这些web元素中很少有不同的html标签'DIV'。 Below images. 下图。 Please help me to find the row count. 请帮我查一下行数。

在此输入图像描述 在此输入图像描述

If you want to only grab the Row count of the grid, instead of using the A tag, you could use the DIV tag of each row. 如果您只想获取网格的行数,而不是使用A标记,则可以使用每行的DIV标记。

For that you should start by inspecting your grid and find the parent div (the one that holds all of the grid contents but without the header) and take its HTML class 为此,您应该首先检查您的网格并找到父div(包含所有网格内容但没有标题的那个)并获取其HTML类

After that, you find the DIV for each row (probably the immediate parent of your A tag element, if not one level above) and also take its HTML class. 之后,您会找到每行的DIV(可能是您的A标记元素的直接父级,如果不是上面的一个级别),也可以使用其HTML类。 You will notice that the class is the same for each row. 您会注意到每行的类是相同的。 If not you can easily find a pattern and think of a regular expression that suits them all. 如果没有,你可以很容易地找到一个模式,并想出一个适合他们的正则表达式。

To inspect elements here I recommend using the browser inspection, because there are some elements that UFT Spy feature cannot find. 要检查元素,我建议使用浏览器检查,因为有一些UFT Spy功能无法找到的元素。 If you can't use the browser inspection tool, you can do it with UFT Spy feature, but it will be a little harder to inspect the elements you want. 如果你不能使用浏览器检查工具,你可以使用UFT Spy功能,但检查你想要的元素会有点困难。 Pay close attention to this. 密切关注这一点。

With both parent div class and rows div class you can create two description objects and work with them. 使用父div类和行div类,您可以创建两个描述对象并使用它们。 Here is a brief example 这是一个简短的例子

Dim parent : Set parent=Description.Create
    parent("micclass").Value="WebElement"
    parent("html tag").Value = "DIV"
    parent("class").Value="ui-grid ng-binding ng-scope your-parent-div-class"    ' change the class accordingly

Dim rows : Set rows = Description.Create
    rows("micclass").Value = "WebElement"
    rows("html tag").Value = "DIV"
    rows("class"). Value = "ui-grid ng-binding ng-scope your-rows-div-class"    ' change the class accordingly

Dim objParent : Set objParent = Browser("CreationTime:=0").Page("title:=.*").ChildObjects(parent) 
If objParent.count > 0 then
    Dim objRows : Set objRows = objParent(0).ChildObjects(rows)
    MsgBox objRows.Count
Else
    MsgBox "Something wrong with your parent description object" 
End If

This specific code was not tested and the changes in classes used are required! 此特定代码未经过测试,所需的类更改是必需的! I am far from UFT so I'm not able to test this now but the solution shouldn't be far from this. 我离UFT很远,所以我现在无法测试,但解决方案不应该远离这个。 I had to implement a function to grab the whole grid for my project and the technology used was the Angular ui-grid. 我必须实现一个函数来抓取我的项目的整个网格,所使用的技术是Angular ui-grid。 Part of my code was exactly getting the row objects to work with. 我的部分代码正是让行对象正常工作。

By looking at your screenshot it looks like you have the same technology implemented in your page so this should work for you. 通过查看截图,您看起来在页面中实现了相同的技术,因此这应该适合您。 Bear in mind that if the developers have implemented Infinite Scroll in the grid, you will have to scroll down to get proper row count, because the rows in HTML are loaded in DOM as you scroll (similar to Facebook behavior) and this is considerably more complex to achieve (but it also can be done) 请记住,如果开发人员在网格中实现了无限滚动,则必须向下滚动才能获得正确的行数,因为HTML中的行在滚动时加载到DOM中(类似于Facebook行为),这是相当多的实现复杂(但也可以做到)

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM