This is a migrated thread and some comments may be shown as answers.

What is the difference between all these three methods?

1 Answer 81 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stanislav
Top achievements
Rank 1
Stanislav asked on 23 Apr 2013, 06:15 AM
Hello Telerik,

What is the difference between all these three methods: .Refresh() of FrameworkElement, .RefreshVisualTrees() of WpfWindow and .RefreshRoot() of VisualFind. In which cases should I use every method?

How can I wait in the script till the moment when the tab is opened and I can search for inner element again? Currently, I am experienced with the sync issue. The tab is opened, but the inner tab couldn't be found even though it is displayed. I have to add Thread.Sleep(1000) to wait for the element update to be able to get the inner tab.

Thank you.

Kind Regards,
Stanislav Hordiyenko

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 25 Apr 2013, 12:16 PM
Hello Stanislav,

FrameworkElement.Refresh() - 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.  

VisualFind.RefreshRoot() - When working with WPF applications, this method refreshes the owner app for this Find object. Internally calls this.OwnerApp.RefreshVisualTrees().

WpfWindow.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>("Tab");
 
//Wait for element to exists. This will also refresh the app visual tree.
tab.Wait.ForExists(30000);

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.

Regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Stanislav
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or