public static bool click_Button_in_Window(this API_GuiAutomation guiAutomation, string windowTitle, string buttonText, bool animateMouse, int timesToTry) { Func <bool> check = () => { var o2Timer = new O2Timer("click_Button_in_Window").start(); var scriptErrorWindow = guiAutomation.window(windowTitle); if (scriptErrorWindow.isNull()) { } //"didn't find window with title: {0}".error(windowTitle); else { var button = scriptErrorWindow.button(buttonText); if (button.isNull()) { } // "didn't find button with text: {0}".error(buttonText); else { "Found it: Clicking on button '{0}' in window '{1}' after {2} tries".debug(windowTitle, buttonText, timesToTry); if (animateMouse) { button.mouse(); } try { button.click(); } catch (Exception ex) { "[API_GuiAutomation][click_Button_in_Window] on or after clicking on button".error(ex.Message); } o2Timer.stop(); return(true); } } return(false); }; "Trying to find button '{0}' in window '{1}' for {2} tries".info(windowTitle, buttonText, timesToTry); for (int i = 0; i < timesToTry; i++) { var result = check(); if (result) { return(true); } } "Didn't find button '{0}' in window '{1}' after {2} tries".error(windowTitle, buttonText, timesToTry); return(false); }
//window public static API_GuiAutomation button_Click(this API_GuiAutomation guiAutomation, string windowName, string buttonName) { var window = guiAutomation.window(windowName); if (window.notNull()) { var button = window.button(buttonName); if (button.notNull()) { button.mouse().click(); } } return(guiAutomation); }
public static Window window(this API_GuiAutomation guiAutomation, string windowName, int numberOfTries) { for (int i = 0; i < numberOfTries; i++) { var window = guiAutomation.window(windowName); if (window.notNull()) { "after {0} tries, found window with title: {1}".info(i, windowName); return(window); } guiAutomation.sleep(1000, false); } "after {0} tries, cound not find window with title: {1}".info(numberOfTries, windowName); return(null); }