Reputation: 1280
I need to scroll to an element present in table for a WPF application, the value is dynamically provided during run time.
I have below code which runs fine for small listview as scrollbar moves correctly but does not scroll to elements near the end of a long list.
My list is as below and I scroll using names (A1
, A2
, ...)
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
Issue:
As shown in the output below, the printed lines A1
, A10
, ... from Console.WriteLine(sString)
and the numbers from Console.WriteLine(iSumPosition)
, works only for a few objects off-screen, the scrollbar moves vertically down, but if my list is large and I need scroll many times then scrolling doesn't work any more.
The scroll bar does not scroll to the end for names near the end of the list, only if my list is very small then it scrolls down to very last element as well.
In Debug mode I see that the rows list (Dim rows As IList = _desktop.WPFListView(sObjlocator).FindAll(sObjSublocator)
) does not have the values (names) for elements near the end of the list.
In the output below, we can see names and positions are printed initially but near the end of the long list only positions are printed.
Output:
A1
0.5
A10
1
A11
1.5
A12
2
...
...
...
9.5
10
10.5
Additional info:
Upvotes: 0
Views: 304
Reputation: 31
You could try using a while loop to continually increase the scroll bar value (to scroll down) until the maximum scroll bar value is met. Below I have put together some sample code that demonstrates this when executed against the WPF sample application that ships with Silk Test.
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
Upvotes: 1