首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FindAll不使用WPFListView 17.5获取WPFListView中的所有子对象

FindAll不使用WPFListView 17.5获取WPFListView中的所有子对象
EN

Stack Overflow用户
提问于 2018-04-27 17:32:45
回答 1查看 272关注 0票数 0

我需要滚动到WPF应用程序的表中的元素,该值是在运行时动态提供的。

下面的代码对于小列表视图运行良好,因为滚动条移动正确,但不会滚动到长列表末尾附近的元素。

我的列表如下所示,我使用名称滚动(A1A2,.)

代码语言:javascript
复制
A1   1   3  

A2   1   5

S1   1   3  

Q2   1   5

.....

.....

Z7   1   3  

Z82   1   5

Z9   1   3  

Imports SilkTest.Ntf.Wpf
Public Module Main
  Dim _desktop As Desktop = Agent.Desktop

  Public Sub Main()
    Dim iPosition As Double = 0.5
    Dim iSumPosition As Double = 0.0
    Dim sObjlocator As String = "//WPFListView[@automationId='MyListView']"
    Dim sData As String = "Z118"
    Dim sObjSublocator As String = "//WPFToggleButton[@caption='*']"

    Dim rows As IList = _desktop.WPFListView(sObjlocator).FindAll(sObjSublocator)

    Dim sObjExist As Boolean = False
    For Each row As WPFToggleButton In rows
      Dim sString As String = row.Text
      Console.WriteLine(sString)     '  <--names
      If Trim(sString) = sData Then
        sObjExist = True
        Exit For
      Else
        iSumPosition += iPosition
        Console.WriteLine(iSumPosition)  ' <--Position

       _desktop.WPFListView(sObjlocator).ScrollToPosition(iSumPosition, Orientation.Vertical)
      End If 
    Next
  End Sub
End Module

发行:

如以下输出所示,打印行A1A10,.从Console.WriteLine(sString)和来自Console.WriteLine(iSumPosition)的数字,只适用于屏幕外的几个对象,滚动条垂直向下移动,但是如果我的列表很大而且我需要滚动很多次,那么滚动就不能再工作了。

滚动条不会滚动到靠近列表末尾的名称,只有当我的列表非常小时,它也会向下滚动到最后一个元素。

在调试模式中,我看到行列表(Dim rows As IList = _desktop.WPFListView(sObjlocator).FindAll(sObjSublocator))在列表末尾附近没有元素的值(名称)。

在下面的输出中,我们可以看到名称和位置是最初打印出来的,但是在长列表的末尾只有位置被打印出来。

输出:

代码语言:javascript
复制
A1
0.5
A10
1
A11
1.5
A12
2

...

...

...

9.5

10

10.5

附加信息:

  • 定位器类型为WPFScrollBar。
  • SilkTest中的WPF预填充表单设置为: yes
  • 使用自动化测试工具:微焦点SilkTest 17.5
EN

回答 1

Stack Overflow用户

发布于 2018-05-02 10:33:06

您可以尝试使用while循环不断地增加滚动条值(以向下滚动),直到达到最大滚动条值为止。下面,我已经收集了一些示例代码,这些代码在执行时演示了这一点,该示例应用程序与丝绸测试一起附带WPF示例应用程序。

代码语言:javascript
复制
Imports SilkTest.Ntf.Wpf
Public Module Main
Dim _desktop As Desktop = Agent.Desktop

Public Sub Main()

    With _desktop.WPFWindow("@caption='WPF Sample Application'")
        .SetActive()
        .WPFMenu().Select("/Controls/Basic Controls")
    End With

    With _desktop.WPFWindow("@caption='Basic Controls'")
        .WPFTabControl("@automationId='tabControl'").Select("ScrollBar")
        Dim sScrollBar As WPFScrollBar
        sScrollBar = .WPFScrollBar("//WPFTabControl[@automationId='tabControl']/WPFScrollBar[2]")
        'Set the scroll bar to the top
        sScrollBar.SetValue(0.0)

        System.Threading.Thread.Sleep(1000)

        Dim iPosition As Double
        iPosition = 0.0

        While sScrollBar.Value < sScrollBar.Maximum
            Console.WriteLine("scroll Bar Maximum  " + sScrollBar.Maximum.ToString)
            Console.WriteLine("scroll Bar Value  " + sScrollBar.Value.ToString)

            'Set Scroll bar position
            sScrollBar.SetValue(iPosition)
            'Return text within scroll          
            Console.WriteLine(.WPFTextBox("@automationId='txtScrollBarEvents'").Text)
            'Increment scroll bar position for each iteration
            iPosition = iPosition + 0.1
            System.Threading.Thread.Sleep(1000)
        End While   

        .Close()
  End With

  End Sub
End Module
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50067521

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档