Automation.UI.Examples.Example1.PatternExample C# (CSharp) Method

PatternExample() private method

private PatternExample ( ) : void
return void
        private void PatternExample()
        {
            var root = AutomationElement.RootElement;
            var window = UITree.Query(root).UsingTreeWalkerEngine()
                // Query 1.
                .FindChildren().Where()
                .Name().Contains("Microsoft Visual Studio")
                .And()
                .Type().Is(ControlType.Window)
                .Select().FirstResult();

            var windows = UITree.Query(root).UsingTreeWalkerEngine()
                // Query 2.
                .FindChildren().Where()
                .Name().Contains("Microsoft Visual Studio")
                .And()
                .Type().Is(ControlType.Window)
                .Select().AllResults();

            // Execute using the 'Window' pattern.
            window.Execute<WindowPattern>(p => p.SetWindowVisualState(WindowVisualState.Minimized));
            // Can also be called on a collection of UI components.
            windows.Execute<WindowPattern>((p, c) => p.SetWindowVisualState(WindowVisualState.Minimized));

            // Or, using the .Pattern() method (only available on single components).
            window.Pattern<WindowPattern>().SetWindowVisualState(WindowVisualState.Minimized);
        }

Usage Example

        public static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            var example = new Example1();
            example.QueryExample();
            example.QueryBuilderExample();
            example.PatternExample();
        }
All Usage Examples Of Automation.UI.Examples.Example1::PatternExample