What is the difference between all these three methods?

2 posts, 0 answers
  1. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 23 Apr 2013 Link to this post

    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
  2. Plamen
    Plamen avatar
    8 posts

    Posted 25 Apr 2013 Link to this post

    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.

    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
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top