internal static IUiElement InvokeContextMenu(this IUiElement inputObject, HasControlInputCmdletBase cmdlet, int x, int y) { IUiElement resultElement = null; try { if (!cmdlet.ClickControl( cmdlet, inputObject, new ClickSettings() { RightClick = true, RelativeX = (x < 0 ? Preferences.ClickOnControlByCoordX : x), RelativeY = (y < 0 ? Preferences.ClickOnControlByCoordY : y) })) { } } catch (Exception) { throw new Exception("failed to click on the control"); } // 20140116 // what are these x and y? // int x = Cursor.Position.X; // int y = Cursor.Position.Y; var contextMenuSearcher = AutomationFactory.GetSearcherImpl <ContextMenuSearcher>(); var contextMenuSearcherData = new ContextMenuSearcherData { InputObject = inputObject, ProcessId = inputObject.GetCurrent().ProcessId }; var elementsMenuRoot = contextMenuSearcher.GetElements( contextMenuSearcherData, Preferences.Timeout); resultElement = elementsMenuRoot.First(element => null != element); return(resultElement); }
internal static IUiElement InvokeContextMenu(this IUiElement inputObject, HasControlInputCmdletBase cmdlet, int x, int y) { IUiElement resultElement = null; try { if (!cmdlet.ClickControl( cmdlet, inputObject, new ClickSettings() { RightClick = true, RelativeX = (x < 0 ? Preferences.ClickOnControlByCoordX : x), RelativeY = (y < 0 ? Preferences.ClickOnControlByCoordY : y) })) { } } catch (Exception) { throw new Exception("failed to click on the control"); } // 20140116 // what are these x and y? // int x = Cursor.Position.X; // int y = Cursor.Position.Y; var contextMenuSearcher = AutomationFactory.GetSearcherImpl<ContextMenuSearcher>(); var contextMenuSearcherData = new ContextMenuSearcherData { InputObject = inputObject, ProcessId = inputObject.GetCurrent().ProcessId }; var elementsMenuRoot = contextMenuSearcher.GetElements( contextMenuSearcherData, Preferences.Timeout); resultElement = elementsMenuRoot.First(element => null != element); return resultElement; }