static void Main(string[] args) { System.Diagnostics.Process.Start("calc"); Thread.Sleep(3000); //Sleep 3 sconds to wait calculator launched try { //Get the destkop element AutomationElement elemDesktop = AutomationElement.RootElement; //Search the Application main window by title from all children PropertyCondition pCondition = new PropertyCondition(AutomationElement.NameProperty, "Calculator"); AutomationElement elemApplicationWindow = elemDesktop.FindFirst(TreeScope.Children, pCondition); //Search the 1 button AutomationElement btnOne = elemApplicationWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "1")); InvokePattern invokePattern1 = btnOne.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern1.Invoke(); AutomationElement btnPlus = elemApplicationWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Add")); InvokePattern invokePatternP = btnPlus.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePatternP.Invoke(); AutomationElement btnTwo = elemApplicationWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "2")); InvokePattern invokePattern2 = btnTwo.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern2.Invoke(); AutomationElement btnE = elemApplicationWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Equals")); InvokePattern invokePatternE = btnE.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePatternE.Invoke(); //Verify the result by get the Name property AutomationElement labelResult = elemApplicationWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "150")); if (labelResult.Current.Name == "3") { Console.WriteLine("Test case pass!"); } else { Console.WriteLine("Test case fail!"); } } catch (Exception) { Console.WriteLine("Test case error!"); } }
} //open new private static AutomationElement InvokeAndCache(string search_term, IntPtr handle) { AutomationElement search = null; try { AutomationElement aeDesktop = AutomationElement.RootElement; AutomationElement aeBrowser = AutomationElement.FromHandle(handle); // Set up the request. CacheRequest cacheRequest = new CacheRequest(); cacheRequest.AutomationElementMode = AutomationElementMode.None; cacheRequest.TreeFilter = Automation.ControlViewCondition; cacheRequest.Add(AutomationElement.ControlTypeProperty); cacheRequest.Add(InvokePattern.Pattern); System.Windows.Automation.Condition conLocation = new OrCondition( new PropertyCondition(AutomationElement.NameProperty, "Navigation Toolbar"), new PropertyCondition(AutomationElement.NameProperty, "Панель навигации")); //russian name of the tab AutomationElement navigation = null; navigation = aeBrowser.FindFirst(TreeScope.Descendants, conLocation); cacheRequest.Push(); if (navigation != null) { AutomationElementCollection elList = navigation.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); if (elList != null && elList.Count > 1) { search = elList[elList.Count - 1]; } } if (search != null) { Util.BringToFront(handle); InvokePattern iPattern = search.GetCachedPattern(InvokePattern.Pattern) as InvokePattern; cached = search; if (iPattern != null) { iPattern.Invoke(); Util.SimulateMessage(search_term, true); Util.Debuglog("cached then invoked : " + search_term); } //if iPattern } //if cacheRequest.Pop(); } catch (Exception ex) { Util.Debuglog(ex.Message); } //try catch return(search); }
public void CloseReport() { if (reportOpen) { AutomationElement closeButton = window.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "CloseReport")); if (closeButton != null) { InvokePattern invoke = (InvokePattern)closeButton.GetCurrentPattern(InvokePattern.Pattern); invoke.Invoke(); } else { Debug.WriteLine("### Close button named 'CloseReport' not found"); } reportOpen = false; } }
void ExecuteButtonInvoke(string automationID) { //Create query condition object, there are two conditions. //1. Check AutomationID //2. Check Control Type Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.AutomationIdProperty, automationID), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)); AutomationElement btn = calcWindow.FindAll(TreeScope.Descendants, conditions)[0]; //Obtain the InvokePattern interface InvokePattern invokeptn = (InvokePattern)btn.GetCurrentPattern(InvokePattern.Pattern); //Click button by Invoke interface invokeptn.Invoke(); }
/// <summary> /// Method performs the Click Action on specified control /// </summary> /// <returns>bool(Click Success - TRUE or Failure - FALSE)</returns> public static bool DoClick() { result = false; try { InvokePattern ptnInvoke = childElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; System.Threading.Thread.Sleep(5000); ptnInvoke.Invoke(); result = true; } catch (ElementNotEnabledException ex) { Console.Write(ex); result = false; } return(result); }
static void TEST_DivButton(AutomationElement divButton, AutomationElement aeEqButton, AutomationElement aeInputBox) { Console.WriteLine("\nRunning TEST_DivButton"); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Setting input to '69'"); ValuePattern vpInputBox = (ValuePattern)aeInputBox.GetCurrentPattern(ValuePattern.Pattern); vpInputBox.SetValue("69"); Console.WriteLine("Div Button Click"); InvokePattern ipDivButton = (InvokePattern)divButton.GetCurrentPattern( InvokePattern.Pattern); ipDivButton.Invoke(); Thread.Sleep(1000); Console.WriteLine("Setting input to '7'"); vpInputBox.SetValue("7"); Console.WriteLine("Div Button Click"); InvokePattern ipEqButton = (InvokePattern)aeEqButton.GetCurrentPattern( InvokePattern.Pattern); ipEqButton.Invoke(); Thread.Sleep(1000); TextPattern tpTextBox2 = (TextPattern)aeInputBox.GetCurrentPattern(TextPattern.Pattern); string result = tpTextBox2.DocumentRange.GetText(-1); if (result.Equals("9,85714285714286")) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("PASSED"); } else { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("FAILED"); } Console.ForegroundColor = ConsoleColor.White; }
private void InvokeMenuItem(AutomationElement item) { object pattern; if (!item.Current.IsEnabled) { throw new Exception("SubMenuItem is not enabled"); } if (item.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) { InvokePattern invoke = (InvokePattern)pattern; invoke.Invoke(); return; } throw new Exception("SubMenuItem does not contain InvokePattern"); }
public void ClickOnBackButtonMainMenu() { AutomationElement mainMenu = GetMainMenuElement(); AutomationElement homeButton = GetElementByAutomationID(mainMenu, "Menu.Back"); InvokePattern homeInvoke = homeButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; try { homeInvoke.Invoke(); } catch { Trace.TraceWarning("back button on main menu view is not available"); } GetMainMenuElements(); }
/// <summary> /// Close FileNowAvailable window /// </summary> /// <param name="docName">Document name</param> public static void CloseFileNowAvailable(string docName) { var desktop = AutomationElement.RootElement; Condition multiCondition = new OrCondition(new PropertyCondition(AutomationElement.NameProperty, docName + ".docx [Read-Only] - Word"), new PropertyCondition(AutomationElement.NameProperty, docName + @".docx - Read-Only - Word")); AutomationElement document = WaitForElement(desktop, multiCondition, TreeScope.Children, true); AutomationElement FileNowAvailableDialog = WaitForElement(document, new PropertyCondition(AutomationElement.NameProperty, "File Now Available"), TreeScope.Children, true); if (FileNowAvailableDialog == null) { return; } Condition Cancel_button = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Cancel")); AutomationElement item_Cancel = FileNowAvailableDialog.FindFirst(TreeScope.Descendants, Cancel_button); InvokePattern Pattern_Cancel = (InvokePattern)item_Cancel.GetCurrentPattern(InvokePattern.Pattern); Pattern_Cancel.Invoke(); }
public void UploadFile(string filePath) { //Name file path by Developer AutomationElement OpenDialog = null; AutomationElement EditElement = null; AutomationElement SubmitElement = null; //Get opendialog element JWait.WaitUntil(() => { AutomationElement Desktop = AutomationElement.RootElement; Condition OpenDialogConditon = new AndCondition( new PropertyCondition(AutomationElement.NameProperty, "打开"), new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "对话框") ); OpenDialog = Desktop.FindFirst(TreeScope.Descendants, OpenDialogConditon); if (OpenDialog == null) { throw new Exception(); } }, 30); //Get Edit element an set value to input Condition EditConditon = new AndCondition( new PropertyCondition(AutomationElement.NameProperty, "文件名(N):"), new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"), new PropertyCondition(AutomationElement.IsValuePatternAvailableProperty, true) ); EditElement = OpenDialog.FindFirst(TreeScope.Descendants, EditConditon); ValuePattern EditAction = EditElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; EditAction.SetValue(filePath); //Get submit element and click the button Condition SubmitConditon = new AndCondition( new PropertyCondition(AutomationElement.NameProperty, "打开(O)"), new PropertyCondition(AutomationElement.ClassNameProperty, "Button"), new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "按钮") ); SubmitElement = OpenDialog.FindFirst(TreeScope.Children, SubmitConditon); InvokePattern SubmitAction = SubmitElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; SubmitAction.Invoke(); }
public void NewSheetNotEmpty() { //ClickFileMenuItem(); for (int i = 0; i < 5; i++) { LoadImage(PROJECT_PATH + @"resources\test_images\small\", "green_square_small.png"); } //click file-new ClickFileMenuItem(); AutomationElement fileNew = GetElement("menuItemNewSheet"); InvokePattern fileNewPat = (InvokePattern)fileNew.GetCurrentPattern(InvokePattern.Pattern); fileNewPat.Invoke(); //verify main window still there //mainWindow = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Atlas Engine")); //Assert.IsNotNull(mainWindow); //check for pop up window\ AutomationElement popUp = null; int cnt = 0; do { Console.WriteLine("Looking for popup window..."); popUp = mainWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Are You Sure?")); cnt++; Thread.Sleep(100); } while (null == popUp && cnt < 50); Assert.IsNotNull(popUp); //click yes button AutomationElement btnYes = popUp.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Yes")); Assert.IsNotNull(btnYes); InvokePattern btnPattern = (InvokePattern)btnYes.GetCurrentPattern(InvokePattern.Pattern); btnPattern.Invoke(); //verify default settings VerifyDefaultSettings(); }
private void button1_Click(object sender, EventArgs e) { //open notepad Process myNotepad = new Process(); myNotepad.StartInfo.FileName = "notepad.exe"; myNotepad.Start(); myNotepad.WaitForInputIdle(); //get a handle on the notepad window PropertyCondition findWindow = new PropertyCondition(AutomationElement.ClassNameProperty, "Notepad"); AutomationElement myNotepadWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, findWindow); //make sure we have a valid handle if (myNotepadWindow == null) { MessageBox.Show("invalid notepad window handle"); return; } //bring window to front for send keys myNotepadWindow.SetFocus(); //send a text string SendKeys.SendWait("testing"); //close notepad PropertyCondition closeButtonCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, "Close"); AutomationElement closeButton = myNotepadWindow.FindFirst(TreeScope.Descendants, closeButtonCondition); //make sure we have a valid handle to the close button if (closeButton == null) { MessageBox.Show("invalid notepad close button handle"); return; } //click no to not save the document Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, myNotepadWindow, TreeScope.Descendants, WindowOpenOnNotepadClose); //click the close button InvokePattern closeButtonInvokePattern = closeButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; closeButtonInvokePattern.Invoke(); }
/// <summary> /// search inside firefox /// </summary> /// <param name="search_term"></param> private static void searchInFireFox(string search_term) { //search using firefox if (oldproc != null && oldproc.HasExited == false && cached != null) { object cachedPattern; if (true == cached.TryGetCachedPattern(InvokePattern.Pattern, out cachedPattern)) { InvokePattern iPattern = cachedPattern as InvokePattern; Util.BringToFront(oldproc.MainWindowHandle); if (iPattern != null) { iPattern.Invoke(); Util.SimulateMessage(search_term, true); } Util.Debuglog("Invoked within cached :" + search_term); } return; } // Process firefox = null; if (oldproc != null && oldproc.HasExited == true) { oldproc.Close(); } else { firefox = oldproc; Util.Debuglog("firefox=oldproc"); }; cached = null; if (firefox == null) { firefox = Util.FindByName("firefox"); } if (firefox != null) { cached = InvokeAndCache(search_term, firefox.MainWindowHandle); oldproc = firefox; } //if else if (open_new(search_term) == false) { Utils.ErrorHandle.notify_user("Could not search with firefox"); } } //
//点击button,使用该方法点击按钮可能触发两次连续的点击操作, //如果连续触发两次点击对操作有影响,请用leftClickAutomationElement()方法代替。 //UIAutomation框架不靠谱啊,此方法非常不靠谱 public static bool clickButton(AutomationElement ae) { object temp; if (ae.TryGetCurrentPattern(InvokePattern.Pattern, out temp)) { try { InvokePattern pattern = temp as InvokePattern; pattern.Invoke(); return(true); } catch (Exception e) { return(false); } } return(false); }
/// <summary> /// Close opened document by UI automation /// </summary> /// <param name="docName">Document name</param> /// <param name="isreadonly">A bool value indicate if the document is readonly</param> public static void CloseDocumentByUI(string docName, bool isreadonly = false) { var desktop = AutomationElement.RootElement; AutomationElement document = null; if (isreadonly) { document = WaitForElement(desktop, new PropertyCondition(AutomationElement.NameProperty, docName + ".docx [Read-Only] - Word"), TreeScope.Children, true); } else { document = WaitForElement(desktop, new PropertyCondition(AutomationElement.NameProperty, docName + ".docx - Word"), TreeScope.Children, true); } Condition Close_button = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Close")); AutomationElement item_Close = document.FindFirst(TreeScope.Descendants, Close_button); InvokePattern Pattern_Close = (InvokePattern)item_Close.GetCurrentPattern(InvokePattern.Pattern); Pattern_Close.Invoke(); }
internal void pattern_Invoke(Type expectedException, CheckType checkType) { string call = "Invoke()"; try { m_pattern.Invoke(); } catch (Exception actualException) { if (Library.IsCriticalException(actualException)) { throw; } TestException(expectedException, actualException, call, checkType); return; } TestNoException(expectedException, call, checkType); }
/// <summary> /// Delete the defaut word empty format /// </summary> public static void DeleteDefaultWordFormat() { Process[] pro = Process.GetProcessesByName("WINWORD"); string title = ""; foreach (Process p in pro) { title = p.MainWindowTitle; if (title == "Word") { var desktop = AutomationElement.RootElement; AutomationElement wordFormat = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Word")); Condition Close_button = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Close")); AutomationElement item_Close = wordFormat.FindFirst(TreeScope.Descendants, Close_button); InvokePattern Pattern_Close = (InvokePattern)item_Close.GetCurrentPattern(InvokePattern.Pattern); Pattern_Close.Invoke(); break; } } }
public void AddRemoveElementTest() { InvokePattern addAction = (InvokePattern)btnAddTextboxElement.GetCurrentPattern(InvokePattern.Pattern); InvokePattern removeAction = (InvokePattern)btnRemoveTextboxElement.GetCurrentPattern(InvokePattern.Pattern); addAction.Invoke(); Thread.Sleep(1000); var newEditElement = panel1Element.FindFirst(TreeScope.Children, new PropertyCondition(AEIds.ControlTypeProperty, ControlType.Edit)); var vp = (ValuePattern)newEditElement.GetCurrentPattern(ValuePattern.Pattern); Action getControlTypeAction = () => Console.WriteLine(newEditElement.Current.BoundingRectangle); Action appendDotAction = () => vp.SetValue(vp.Current.Value + "."); AssertWontRaise <Exception> (getControlTypeAction, "get control type"); AssertWontRaise <Exception> (getControlTypeAction, "append '.'"); removeAction.Invoke(); Thread.Sleep(1000); AssertRaises <ElementNotAvailableException> (getControlTypeAction, "get control type"); AssertRaises <ElementNotAvailableException> (getControlTypeAction, "append '.'"); }
public static void executePattern(AutomationElement subject, AutomationPattern inPattern) { try { switch (inPattern.ProgrammaticName) { case "InvokePatternIdentifiers.Pattern": { InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern); invoke.Invoke(); break; } case "SelectionItemPatternIdentifiers.Pattern": { SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern); select.Select(); break; } case "TogglePatternIdentifiers.Pattern": { TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern); toggle.Toggle(); break; } case "ExpandCollapsePatternIdentifiers.Pattern": { ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern); exColPat.Expand(); break; } } } catch (Exception ex) { //ignore for now issue with infragistics elements not getting proper states //throw; } }
public void Invoke(AutomationElement dataItem) { if (DataType == "Button") { AutomationElement cell = GetCellContent(dataItem, true); object obj; if (cell.TryGetCurrentPattern(InvokePattern.Pattern, out obj)) { InvokePattern invoke = (InvokePattern)obj; invoke.Invoke(); return; } throw new Exception("DataGridCell " + Name + " does not contain an InvokePattern"); } else { throw new Exception("Cannot invoke column of this type, expecting a button column"); } }
public override UIHandlerAction HandleWindow(IntPtr topLevelhWnd, IntPtr hwnd, Process process, string title, UIHandlerNotification notification) { GlobalLog.LogDebug("Display Configuration window found."); AutomationElement window = AutomationElement.FromHandle(topLevelhWnd); // get a reference the address bar GlobalLog.LogDebug("Finding and clicking the OK Button"); Condition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "1"); AutomationElement okBtn = window.FindFirst(TreeScope.Descendants, cond); object patternObject; okBtn.TryGetCurrentPattern(InvokePattern.Pattern, out patternObject); InvokePattern invokePattern = patternObject as InvokePattern; invokePattern.Invoke(); GlobalLog.LogDebug("Waiting for theme to be applied..."); process.WaitForExit(); return(UIHandlerAction.Abort); }
public void OpenTile(string tileTitle) { AutomationElement titleView = GetElementByClassName(GetDisplaysMain(), "CaptionDisplayPanel"); foreach (AutomationElement tile in titleView.FindAll(TreeScope.Subtree, Condition.TrueCondition)) { AutomationElement rootTile = GetElementByAutomationID(tile, "TileItemUserControl.Button"); if (rootTile != null) { AutomationElement text = GetElementByAutomationID(tile, "TileItemUserControl.Text"); string textOfCurrentTile = text.Current.Name; if (textOfCurrentTile == tileTitle) { InvokePattern tileInvoke = rootTile.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; //Click on Tile tileInvoke.Invoke(); } } } WalkThroughViewableTiles(); }
protected override void Execute() { Condition controlCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, ControlId); var element = MainWindow.FindFirst(TreeScope.Children, controlCondition); if (element != null) { try { object pattern = element.GetCurrentPattern(InvokePattern.Pattern); if (pattern != null && pattern is InvokePattern) { InvokePattern invokePtr = pattern as InvokePattern; invokePtr.Invoke(); } } catch (Exception) { } } }
public void TestInvokeEvent() { AutomationElement startButton = AutomationElementTest.GetStartButton(); BasicChangeHandler handler = new BasicChangeHandler(); Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, startButton, TreeScope.Element, new AutomationEventHandler(handler.HandleEvent)); handler.Start(); InvokePattern invoke = (InvokePattern)startButton.GetCurrentPattern(InvokePattern.Pattern); invoke.Invoke(); System.Windows.Forms.SendKeys.SendWait("{ESC}"); Assert.IsTrue(handler.Confirm()); Assert.IsNotNull(handler.EventSource); Automation.RemoveAutomationEventHandler( InvokePattern.InvokedEvent, startButton, new AutomationEventHandler(handler.HandleEvent)); }
private void PerformOperation(object sender, RoutedEventArgs e) { WaitCallback callback = delegate { AutomationElement windowElt = AutomationElement.FromHandle(_handle); // Locate this UserControl with AutomationId var btnElt = windowElt.FindFirst(TreeScope.Descendants, new PropertyCondition( AutomationElement.AutomationIdProperty, "ID_InvokeButton")); InvokePattern pattern = btnElt.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; if (pattern != null) // Button implements the IInvokeProvider interface { pattern.Invoke(); } }; ThreadPool.QueueUserWorkItem(callback); }
public static void InvokeAutomationElement(AutomationElement automationElement) { InvokePattern invokePattern = null; try { invokePattern = automationElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; } catch (ElementNotEnabledException) { return; } catch (InvalidOperationException) { return; } catch (InvalidCastException) { return; } invokePattern.Invoke(); }
/// <summary> /// Close checkin pane in opening word /// </summary> /// <param name="filename">file name</param> /// <param name="keepCheckOut">Bool value indicate whether to keep check out when do checkIn</param> public static void CloseCheckInPane(string filename, bool keepCheckOut) { var desktop = AutomationElement.RootElement; Condition Con_Document = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, filename + ".docx - Word")); AutomationElement item_Document = desktop.FindFirst(TreeScope.Children, Con_Document); Condition Con_Checkin = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "Check In")); AutomationElement item_Checkin = WaitForElement(item_Document, Con_Checkin, TreeScope.Children, true); if (keepCheckOut) { Condition Con_CheckBox = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Keep the document checked out after checking in this version.")); AutomationElement item_CheckBox = item_Checkin.FindFirst(TreeScope.Descendants, Con_CheckBox); TogglePattern Pattern_CheckBox = (TogglePattern)item_CheckBox.GetCurrentPattern(TogglePattern.Pattern); Pattern_CheckBox.Toggle(); } Condition Con_Yes = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "OK")); AutomationElement item_Yes = item_Checkin.FindFirst(TreeScope.Descendants, Con_Yes); InvokePattern Pattern_Yes = (InvokePattern)item_Yes.GetCurrentPattern(InvokePattern.Pattern); Pattern_Yes.Invoke(); }
public bool SetDefaultDevice(AutomationElement aeSoundDialog, AutomationElement aeDevice) { //if (!(deviceIndex < recordingDevices.Count)) // return false; SelectionItemPattern select = aeDevice.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; select.Select(); AutomationElement aeSetDefaultBtn = aeSoundDialog.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, CID_SET_DEFAULT_BTN.ToString())); if (!aeSetDefaultBtn.Current.IsEnabled) { return(false); } InvokePattern invokePattern = aeSetDefaultBtn.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke(); return(true); }
private void OpenTile(string languageShortDef) { AutomationElement titleView = GetElementByClassName(GetDisplaysMain(), "CaptionDisplayPanel"); foreach (AutomationElement tile in titleView.FindAll(TreeScope.Subtree, Condition.TrueCondition))// new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "ReflectableUserControl"))) { AutomationElement rootTile = GetElementByAutomationID(tile, "TileItemUserControl.Button"); if (rootTile != null) { AutomationElement text = GetElementByAutomationID(tile, "TileItemUserControl.Text"); string textOfCurrentTile = text.Current.Name; if (!invokedList.Contains(textOfCurrentTile) && textOfCurrentTile != "HMI state") { if (!textOfCurrentTile.Contains("HMI")) { invokedList.Add(textOfCurrentTile); InvokePattern stationInvoke = rootTile.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; stationInvoke.Invoke(); TakeScreenShotFromSmartHMI(languageShortDef, string.Format("{0}_KUKA.SunriseMobility {1} {2}", languageShortDef, Properties.Settings.Default.Version, textOfCurrentTile)); if (textOfCurrentTile.Contains("Safe")) { foreach (AutomationElement item in tile.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "ReflectableUserControl"))) { InvokePattern activationTile = item.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; activationTile.Invoke(); AutomationElement activationTileText = GetElementByAutomationID(tile, "TileItemUserControl.Text"); TakeScreenShotFromSmartHMI(languageShortDef, string.Format("{0}_KUKA.SunriseMobility {1} {2}", languageShortDef, Properties.Settings.Default.Version, activationTileText.Current.Name)); } ClickOnBackButton(); } ClickOnBackButton(); } } } } }
///-------------------------------------------------------------------- /// <summary> /// Invoke support function. /// </summary> /// <param name="automationID"> /// The AutomationID of the target element. /// </param> ///-------------------------------------------------------------------- internal void Invoke(string automationID) { AutomationElement element; element = FindElement(automationID); if (element == null) { Feedback(automationID.ToString() + " could not be found."); return; } if ((bool)element.GetCurrentPropertyValue(AutomationElement.IsEnabledProperty) == false) { Feedback("Element not enabled."); return; } InvokePattern invokePattern = element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke(); Feedback(automationID.ToString() + " invoked."); }