Invoking Actions on Elements
Once you have found an element you can then interact with it. Many different types of interactions are supported like clicking, mouse hover over, mouse wheel-related actions, keyboard clicks etc.
1. Clicking On an Element - invoke a click on a FrameworkElement.
2. Sending Text to a Control - type text content into a FrameworkElement.
3. Mouse Actions - invoking different mouse actions on FrameworkElement.
4. Framework Element Properties and Actions. * UI Element Actions - understanding wrappers. * Telerik Testing Framework Specific Properties - commonly used Properties of Telerik's FrameworkElement. * Telerik Testing Framework Specific Methods - commonly used Methods of Telerik's FrameworkElement. * Getting and Setting Properties on Elements - working with non-built in Properties. 5. Invoking Element Methods - invoke any method attached to an element.
Clicking On an Element
To invoke a UI action, use the User object that is attached to every UI element. For example, to click on an element such as a button, enter code like this:
//In this example app can be a Silverlight application or the MainWindow element of a WPF application
// Click the ShowGuide button.
app.Find.ByName("guideButton").User.Click();
// Right click the ShowGuide button 5 pixels away from the center of the control
app.Find.ByName("guideButton").User.Click(MouseClickType.RightClick,
new System.Drawing.Point(5, 5), OffsetReference.AbsoluteCenter);
'In this example app can be a Silverlight application or the MainWindow of a WPF application
' Click the ShowGuide button.
app.Find.ByName("guideButton").User.Click()
' Right click the ShowGuide button 5 pixels away from the center of the control
app.Find.ByName("guideButton").User.Click(MouseClickType.RightClick, _
New System.Drawing.Point(5, 5), _
OffsetReference.AbsoluteCenter)
Sending Text to a Control
To send text to the control use one of the following lines of code:
searchText.User.TypeText("Abe Lincoln", 100);
searchText.User.KeyPress(System.Windows.Forms.Keys.L, 100);
searchText.User.KeyDown(System.Windows.Forms.Keys.L);
searchText.User.KeyUp(System.Windows.Forms.Keys.L);
searchText.User.TypeText("Abe Lincoln", 100)
searchText.User.KeyPress(Windows.Forms.Keys.L, 100)
searchText.User.KeyDown(Windows.Forms.Keys.L)
searchText.User.KeyUp(Windows.Forms.Keys.L)
Mouse Actions
To perform one of the various possible mouse actions use one of the following lines of code:
admin2.Find.ByType("Thumb").User.DragTo(admin3.Find.ByType("Thumb"));
admin1.User.HoverOver();
admin1.User.MouseEnter(OffsetReference.LeftCenter);
admin1.User.MouseLeave(OffsetReference.RightCenter);
admin1.User.TurnMouseWheel(5, MouseWheelTurnDirection.Backward, false);
admin2.Find.ByType("Thumb").User.DragTo(admin3.Find.ByType("Thumb"))
admin1.User.HoverOver()
admin1.User.MouseEnter(OffsetReference.LeftCenter)
admin1.User.MouseLeave(OffsetReference.RightCenter)
admin1.User.TurnMouseWheel(5, MouseWheelTurnDirection.Backward, False)
Framework Element Properties and Actions
All of the Telerik Testing Framework UI controls derive from the FrameworkElement object. Our FrameworkElement object mirrors as closely as possible XAML's FrameworkElement as defined in MSDN here. For customers interested in our extensibility model, the Silverlight Extension does not expose a UIElement and therefore, our FrameworkElement can be viewed as the combination of Silverlight/WPF's UIElement + FrameworkElement. These are just few examples of the many available properties of our FrameworkElement object:
Property | Description |
---|---|
AutomationId | Retrieves the Automation ID assigned to this element. |
Children | Retrieves a list of elements that are children of this element in the visual tree.|
Clip | Gets or sets the Geometry used to define the outline of the contents of a UI Element. |
Height | Gets or sets the suggested height of a FrameworkElement. |
Opacity | Gets or sets the degree of the object's opacity. |
OpacityMask | Gets or sets the brush used to alter the opacity of regions of this object. |
Width | Gets or sets the suggested width of a FrameworkElement. |
Property | Description |
---|---|
AbsoluteSiblingTagIndex | Returns the sibling tag index of this FrameworkElement relative to its other siblings within the Visual Tree. |
AbsoluteTagIndex | Returns the absolute index of this XAML tag within the entire Visual Tree. |
Application | Gets the Application object that owns this element. |
EnableValidateMouseLocation | Enables or disables the validation of mouse click locations before performing mouse actions. |
Find | Gets the Find object that can be used to search the visual children of this element. |
TagNameIndex | Gets the tag name index of the XAML tag name in the visual tree. |
User | Gets the UI interaction object which allows you to interact with this framework element directly using real mouse and keyboard interactions. |
Wait | Gets a VisualWait object you can use to wait for Visual elements in the Visual Tree. |
XamlTag | Gets the XAML tag name of this FrameworkElement. This is used for hierarchy matching and traversal. |
Property | Description |
---|---|
CastAs<T>() | Returns a FrameworkElement as a strongly-typed control. Does not enforce a tagname to match the type. |
GetChildren() | Returns the child elements of the FrameworkElement.|
GetNextSibling() | Returns the next sibling of the FrameworkElement. |
Parent() | Returns the parent element of the current Framework Element |
ScrollToVisible() | Scrolls the browser so that the Framework Element is visible. |