New to Telerik Test Studio? Download free 30-day trial

Change Silverlight Find Strategy

The default behavior of Test Studio Dev is to time out after a certain interval if the element is not found.

I would like to avoid the Timeout Exception and perform a different set of steps depending on whether the element is found.


This is possible with a coded solution. Change the SilverlightApp or any FrameworkElement VisualFind.Strategy value to WhenNotVisibleReturnNull.

The example below is against this Silverlight demo site. After navigating there, click DataGrid in the left-hand menu. Then add a coded step:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0]; 
FindStrategy originalStrategy = app.Find.Strategy; 
    app.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull; 
    string gridName = "dataGrid"; 
    DataGrid grid = app.Find.ByName<DataGrid>(gridName); 
    if (grid != null) 
        //Perform actions on the DataGrid 
        //You can throw an exception, or perform alternative steps 
        throw new ArgumentException(string.Format("Unable to find the DataGrid named '{0}'!", gridName)); 
    app.Find.Strategy = originalStrategy; 
Dim app As SilverlightApp = ActiveBrowser.SilverlightApps()(0) 
Dim originalStrategy As FindStrategy = app.Find.Strategy 
    app.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull 
    Dim gridName As String = "dataGrid" 
    Dim grid As DataGrid = app.Find.ByName(Of DataGrid)(gridName) 
    If grid IsNot Nothing Then 
        Throw New ArgumentException(String.Format("Unable to find the DataGrid named '{0}'!", gridName)) 
    End If 
    app.Find.Strategy = originalStrategy 
End Try 

Note: As is, the IF portion is executed. You can disable step two (treeview item 'DataGrid' select action) to see the ELSE portion execute.

In this article
Not finding the help you need? Improve this article