// Get the automation element for the button AutomationElement buttonElement = windowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "myButton")); // Set focus on the button buttonElement.SetFocus();
// Get the automation element for the text box AutomationElement textBoxElement = windowElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit))[1]; // Set focus on the text box textBoxElement.SetFocus();In both examples, the automation element representing the UI element to be focused is obtained using the `FindFirst()` or `FindAll()` methods of the `AutomationElement` class and the `SetFocus()` method is then called on the obtained automation element object. The package library for this method is `System.Windows.Automation`.