New to Telerik Test Studio Dev EditionStart a 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.

Solution

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:

C#
    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    FindStrategy originalStrategy = app.Find.Strategy;
    
    try
    {
        app.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
        string gridName = "dataGrid";
        DataGrid grid = app.Find.ByName<DataGrid>(gridName);
        
        if (grid != null)
        {
            grid.Wait.ForVisible();
            //Perform actions on the DataGrid
        }
        else   
        {
            //You can throw an exception, or perform alternative steps
            throw new ArgumentException(string.Format("Unable to find the DataGrid named '{0}'!", gridName));
        }
    }
    finally
    {
        app.Find.Strategy = originalStrategy;
    }

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
Solution
Not finding the help you need?
Contact Support