- Refreshes this FrameworkElement within the VisualTree. Use this method to refresh container controls. For example, if you're searching for a specific element within a dynamic grid, you can use grid.Refresh() before performing the search to ensure that all elements are added into the grid's visual tree.
- When working with WPF applications, this method refreshes the owner app for this Find object. Internally calls this.OwnerApp.RefreshVisualTrees()
- As the method description states, this method refreshes the main visual tree for the application as well as any open Popup visual trees.
Regarding the issue you are experiencing, you should be able to overcome it by changing the application Find Strategy. Here's a sample code:
WpfWindow window = Manager.ActiveApplication.MainWindow;
window.Find.Strategy = FindStrategy.WhenNotVisibleReturnElementProxy;
TabControl tab = window.Find.ByAutomationId<TabControl>(
//Wait for element to exists. This will also refresh the app visual tree.
In the above code, the Find object will actually simply return the object proxy that you can then invoke the
Wait on if the element can’t be found immediately. Wait.ForExists()
internally calls the RefreshRoot()
method. This means that using this code the execution will wait up to the time set(30 seconds in this case), refreshing the visual tree on every 500 ms, and when the element is found will proceed with the next line of code.
Please give it a try and let me know if you need further assistance on this.
the Telerik team