private void ChangeDownloadPath(string targetPath) { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } string currentPath = AutoItX.ControlGetText("[TITLE:Save As; CLASS:#32770]", "", "[CLASS:ToolbarWindow32; INSTANCE:4]"); if (!currentPath.Contains(targetPath)) { AutoItX.WinActivate("[TITLE:Save As; CLASS:#32770]", ""); IntPtr w = AutoItX.WinGetHandle("[TITLE:Save As; CLASS:#32770]", ""); IntPtr c = AutoItX.ControlGetHandle(w, "[CLASS:ToolbarWindow32; INSTANCE:4]"); Rectangle mainWindowPosition = AutoItX.WinGetPos(w); Rectangle refElementPosition = AutoItX.ControlGetPos(w, c); int startX = mainWindowPosition.X + refElementPosition.X + refElementPosition.Width - 10; int startY = mainWindowPosition.Y + refElementPosition.Y + refElementPosition.Height / 2; AutoItX.MouseMove(startX + 15, startY + 25); AutoItX.MouseClick("LEFT", startX + 15, startY + 25); AutoItX.Send("{BACKSPACE}"); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(50)); AutoItX.Send(targetPath); Thread.Sleep(TimeSpan.FromSeconds(1)); AutoItX.Send("{ENTER}"); } }
public static void LogIN() { Process[] isClud = Process.GetProcessesByName("THCludSuit"); // 主目錄 // 測試"看診清單"是否有打開 if (isClud.Length == 0) { AutoItX.Run(@"C:\Program Files (x86)\THESE\杏雲醫療資訊系統\THCloudStarter.exe", @"C:\Program Files (x86)\THESE\杏雲醫療資訊系統\"); //; Wait for the Notepad to become active. The classname "Notepad" Is monitored instead of the window title AutoItX.WinWaitActive("登入畫面"); //; Now that the Notepad window Is active type some text if (AutoItX.ControlGetText("登入畫面", "", "[NAME:txtHospitalExtensionCode]") != "A") { AutoItX.ControlClick("登入畫面", "", "[NAME:txtHospitalExtensionCode]", "LEFT", 2); AutoItX.ControlSend("登入畫面", "", "[NAME:txtHospitalExtensionCode]", "A"); } AutoItX.ControlSend("登入畫面", "", "[NAME:txtPassword]", "IlovePierce4926"); AutoItX.Sleep(500); // [NAME:btnLogin] //AutoItX.ControlClick("登入畫面", "", "[NAME:picLogin]"); AutoItX.ControlClick("登入畫面", "", "[NAME:btnLogin]"); AutoItX.WinActivate("杏雲雲端醫療服務"); AutoItX.WinWaitActive("杏雲雲端醫療服務"); AutoItX.Sleep(2000); } else { AutoItX.WinActivate("杏雲雲端醫療服務"); } }
static void Main(string[] args) { var text = AutoItX.ControlGetText("Untitled - Notepad", "", "[CLASSNN:Edit1]"); //In your case, since you are dealing with handles, you can use: var windowHandle = new IntPtr(0x00788600); var controlHandle = new IntPtr(0x00000000); var text2 = AutoItX.ControlGetText(windowHandle, controlHandle); }
private void ClearTextBox(IntPtr mainWindow, IntPtr textBox) { if (AutoItX.ControlFocus(mainWindow, textBox) == AutoItXSuccess) { string textBoxContent = AutoItX.ControlGetText(mainWindow, textBox); while (!string.IsNullOrEmpty(textBoxContent)) { AutoItX.Send("{BACKSPACE}"); textBoxContent = AutoItX.ControlGetText(mainWindow, textBox); } } }
protected string GetValue(string clazz, int instance) { if (!Running) { return(null); } IntPtr hwnd = GetHandle(clazz, instance); if (hwnd == IntPtr.Zero) { return(""); } return(AutoItX.ControlGetText(process.MainWindowHandle, hwnd)); }
/// <summary> /// Функция считывает данные с не активного поданного контрола /// </summary> /// <param name="element">Наш контол Название ,идентификатор Name</param> /// <returns></returns> public static string ReadFormNotActiv(string[] element) { string parametr = null; while (true) { if (String.IsNullOrWhiteSpace(parametr)) { parametr = AutoItX.ControlGetText(element[0], "", element[1]); } else { break; } } return(parametr); }
private static void IsMainFormActivated() { var i = 0; while (i < 1000) { Thread.Sleep(4000); _mainForm = AutoItX.WinGetHandle("招商银行个人银行专业版_"); AutoItX.WinActivate(_mainForm); if (AutoItX.ControlGetText(_mainForm, AutoItX.ControlGetHandle(_mainForm, "[CLASS:TCMBStyleComboBox72; INSTANCE:1]")) == "功能") { Console.WriteLine("Main Page is now Active."); return; } Console.WriteLine("Waiting for Main Page"); i++; } throw new Exception("Cant Find Main Page!"); }
private static void WaitForLogin(IntPtr loginForm) { var i = 0; while (i < 1000) { Thread.Sleep(2000); if (AutoItX.ControlGetText(loginForm, AutoItX.ControlGetHandle(loginForm, "[CLASS:TCMBStyleComboBox72; INSTANCE:1]")) != "功能") { Thread.Sleep(4000); Console.WriteLine("Successfully LogIn.. "); Console.WriteLine("Closing Login Window."); return; } Console.WriteLine("Logging In."); i++; } throw new Exception("Log In Error!"); }
private void ConnectToDomain() { WaitForWindow(domainWindowTitle); //Check all elements are visible in particular window CheckControlVisibility(domainWindowTitle, disconnectButton); CheckControlVisibility(domainWindowTitle, domainTextbox); CheckControlVisibility(domainWindowTitle, domainDropdown); //Check textbox value and select domain from dropdown string defaultDomainVal = AutoItX.ControlGetText(domainWindowTitle, "", domainTextbox); if (defaultDomainVal != domainName && string.IsNullOrEmpty(defaultDomainVal) == false) { AutoItX.ControlCommand(domainWindowTitle, "", domainDropdown, "AddString", domainName); AutoItX.ControlCommand(domainWindowTitle, "", domainDropdown, "SelectString", domainName); } else { AutoItX.ControlClick(domainWindowTitle, "", connectButton); } Console.WriteLine("-- Connecting to domain"); }
public void TestErrorReport() { try { AutoItX.Send("R"); AutoItX.Sleep(1000); AutoItX.Send("R"); AutoItX.Sleep(2000); AutoItX.Send("{Enter} {Enter} {Enter}"); AutoItX.Sleep(2000); AutoItX.Send("{Down} {Down} {Down} {Down} {Down}"); AutoItX.Sleep(2000); AutoItX.Send("{Enter}"); AutoItX.Sleep(2000); AutoItX.Send("{Right} {Right}"); AutoItX.Sleep(2000); AutoItX.Send("{Enter}"); AutoItX.Sleep(2000); AutoItX.Send("{Right} {Right} {Right}"); AutoItX.Sleep(3000); AutoItX.Send("{Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter} {Enter}"); //MessageBox.Show("Class files of windows ====> " + AutoItX.WinGetClassList()); //AutoItX.Sleep(5000); String strGetCrWinTitle = AutoItX.WinGetTitle("[CLASS:RELY - TRIPTA Innovations Pvt. Ltd.]", "", 10); int flag = AutoItX.WinActivate(strGetCrWinTitle); Console.WriteLine("Flag is =>" + flag); if (flag != 0) { MessageBox.Show("Error occured ========>" + strGetCrWinTitle); Console.WriteLine("Error occured ========>" + strGetCrWinTitle); } //AutoItX.WinActive(strGetCrWinTitle); //MessageBox.Show("Error occured ========>" + strGetCrWinTitle); string errorText = AutoItX.ControlGetText(strGetCrWinTitle, "Error", "Error"); //String errorText = AutoItX.WinGetText("[CLASS:RELY - TRIPTA Innovations Pvt. Ltd.]", "Error"); //Console.WriteLine("Current Window title is : " + AutoItX.WinGetTitle()); //MessageBox.Show("Current Window title is : " + AutoItX.WinGetTitle()); MessageBox.Show("Error description ========>" + errorText); Console.WriteLine("Error description ========>" + errorText); MessageBox.Show("Description of Error page =======>" + Convert.ToString(AutoItX.WinGetHandle("[ACTIVE]"))); Console.WriteLine("Description of Error page =======>" + Convert.ToString(AutoItX.WinGetHandle("[ACTIVE]"))); //Int64 errorText = AutoItX.WinExists("RELY - TRIPTA Innovations Pvt. Ltd", "Error"); //if (errorText == 0 /*"Error"*/) //{ // MessageBox.Show("Error occured in RELY.." + DateTime.Now + " " + AutoItX.ErrorCode() + AutoItX.WinGetText("[ACTIVE]")); // Console.WriteLine(AutoItX.WinGetText("[ACTIVE]")); // Console.ReadKey(); //} /*-------------------------------------------- Error occured in Reports ---------------------------------------- */ AutoItX.Send("{ENTER}"); AutoItX.Sleep(2000); Console.Write("AFTER ERROR {ENTER} KEY IS PRESSED...!"); AutoItX.Send("{ESC} {ESC}"); AutoItX.Sleep(2000); Console.Write("AFTER ERROR {ESC} KEY IS PRESSED TWO TIMES...!"); //MessageBox.Show("Error occured in RELY.." + " " + AutoItX.ErrorCode()); //AutoItX.WinMinimizeAll(); //AutoItX.WinMinimizeAllUndo(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(ex.StackTrace); Console.WriteLine(); MessageBox.Show("Error occured in RELY.." + ex.Message + AutoItX.ErrorCode()); Console.Write("Error occured in RELY.." + ex.Message + AutoItX.ErrorCode()); } finally { AutoItX.WinClose(); MessageBox.Show("RELY will be closing,now.!", "RELY will be closing,now.!", MessageBoxButtons.OK); } }
/// <summary> /// Sends text to file name control of browser open file GUI dialog window and /// presses {Enter} key. Supports single and multiple (from the same folder) /// file(s) upload. Checks whether the dialog was closed afterwards. /// </summary> /// <param name="paths">File(s) with full path</param> public static void Upload(params string[] paths) { if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0])) { throw new ArgumentException( @"Got null or empty parameter(s). Nothing to upload.", nameof(paths)); } // is it multiple files upload? var isMultipleFilesUpload = paths.Length > 1; // waits for dialog window appearance if (AutoItX.WinWait(WindowTitle, string.Empty, 5) == 0) { throw new AggregateException($@"AutoItX: '{WindowTitle}' dialog window not found"); } // get handles of dialog window, OK button, and File Name input controls _windowHandle = AutoItX.WinGetHandle(WindowTitle); _okControlHandle = AutoItX.ControlGetHandle(_windowHandle, OkControlName); _fileNameControlHandle = AutoItX.ControlGetHandle(_windowHandle, FileNameControlName); if ((int)_windowHandle <= 0 || (int)_okControlHandle <= 0) { throw new AggregateException("AutoItX: Cannot get window or/and control handle(s)"); } // activate dialog window (just in case) AutoItX.WinActivate(_windowHandle); // set uploaded files folder as current folder in case of multiple files selection var dir = Path.GetDirectoryName(paths[0])?.Replace(@"\\", @"\"); if (isMultipleFilesUpload && !string.IsNullOrEmpty(dir)) { // change path // mode: 1 -> no control symbols processing, send text "as is" AutoItX.ControlSend( _windowHandle, AutoItX.ControlGetHandle(_windowHandle, FileNameControlName), dir, mode: 1); // press OK button AutoItX.ControlClick(_windowHandle, _okControlHandle); Thread.Sleep(1000); } // create input string for file name control var path1 = string.Empty; foreach (var path in paths) { path1 += (isMultipleFilesUpload ? "\"" + Path.GetFileName(path) + "\" " : path) .Replace(@"\\", @"\"); // check if dialog is still active and activate it if needed if (AutoItX.WinActive(_windowHandle) != 0) { continue; } if (AutoItX.WinActivate(_windowHandle) == 0) { throw new AggregateException( $@"AutoItX: Cannot activate '{WindowTitle}' dialog window. " + "Is it closed, overlapped or desktop is locked?"); } } // due to upper/lower case AutoIt input typos, following workaround is implemented: // input path to File Name control and verify it afterwards; if wrong, input it // over and over until succeed or timed out var sw = new Stopwatch(); sw.Start(); while (AutoItX.ControlGetText(_windowHandle, _fileNameControlHandle) != path1 && sw.Elapsed < TimeSpan.FromSeconds(60)) { AutoItX.ControlSetText(_windowHandle, _fileNameControlHandle, string.Empty); AutoItX.ControlSend(_windowHandle, _fileNameControlHandle, path1, mode: 1); } sw.Stop(); // if input is timed out, throw exception if (sw.Elapsed >= TimeSpan.FromSeconds(60)) { throw new AggregateException($@"AutoItX: Failed to input path '{path1}'"); } // check if dialog is still active and activate it if not if (AutoItX.WinActive(_windowHandle) == 0) { if (AutoItX.WinActivate(_windowHandle) == 0) { throw new AggregateException( $@"AutoItX: Cannot activate '{WindowTitle}' GUI dialog window. " + "Is it closed, overlapped or desktop is locked?"); } } // press OK button AutoItX.ControlClick(_windowHandle, _okControlHandle); // check if the dialog is closed var success = AutoItX.WinWaitClose(_windowHandle, 1); if (success > 0) { return; } // throw exception if dialog is not closed throw new AggregateException( $@"AutoItX: Failed to close '{WindowTitle}' GUI dialog window. Was this " + "window closed manually, desktop locked, or 'File not found' error " + "displayed?"); }
public string ControlGetText(string title, string text, string control, int maxLen = 65535) { return(AutoItX.ControlGetText(title, text, control, maxLen)); }
public string ControlGetText(string control = "", int maxLen = 65535) { return(AutoItX.ControlGetText(thiswindowHandle, ControlGetHandle(control), maxLen)); }
public void Convert() { log.Info(" Begin Convert."); string output; #region Environment try { // 營造環境 log.Info(" Check 處方清單."); if (AutoItX.WinExists("處方清單") == 1) //如果直接存在就直接叫用 { AutoItX.WinActivate("處方清單"); log.Info(" 處方清單 exists."); } else { log.Info(" 處方清單 doesn't exist."); Thesis.LogIN(); // 打開"處方清單", 找不到control,只好用mouse去按 AutoItX.WinActivate("杏雲雲端醫療服務"); // 先maximize AutoItX.WinSetState("杏雲雲端醫療服務", "", 3); //0 close; 1 @SW_RESTORE; 2 @SW_MINIMIZE; 3 @SW_MAXIMIZE AutoItX.MouseMove(280, 280); AutoItX.MouseClick(); AutoItX.Sleep(500); AutoItX.ControlClick("杏雲雲端醫療服務", "", "[NAME:btnPrescription]"); log.Info(" 處方清單 opened."); Thread.Sleep(10000); } // 打開備份 AutoItX.WinWaitActive("處方清單"); AutoItX.ControlClick("處方清單", "", "[NAME:btnBackup]"); log.Info(" 處方清單 exists."); AutoItX.WinActivate("處方清單備份選項"); AutoItX.WinWaitActive("處方清單備份選項"); AutoItX.ControlClick("處方清單備份選項", "", "[NAME:txbBackupPath]", "LEFT", 2); AutoItX.Send("{Tab}"); AutoItX.Send("{Tab}"); AutoItX.Send("{Enter}"); // first choice Desktop // 這裡的等待很重要, 太短來不及讀, 500可以, 100 不行, 200 一半一半, 250 100% AutoItX.Sleep(300); // 尋找XML, 若有就刪除 output = AutoItX.ControlGetText("處方清單備份選項", "", "[NAME:txbBackupPath]"); output += $"\\{_begindate.Year}\\{_begindate.Year}{(_begindate.Month + 100).ToString().Substring(1)}.xml"; if (System.IO.File.Exists(output)) { System.IO.File.Delete(output); } log.Info(" Kill xml files."); // AutoItX.ControlSend("處方清單備份選項", "", "[NAME:txbBackupPath]", "C:\vpn") } catch (Exception ex) { output = string.Empty; log.Error($" Error. {ex.Message}"); Logging.Record_error(ex.Message); } #endregion Environment #region Producing XML string BeginDate = $"{_begindate.Year}{(_begindate.Month + 100).ToString().Substring(1)}{(_begindate.Day + 100).ToString().Substring(1)}"; string EndDate = $"{_enddate.Year}{(_enddate.Month + 100).ToString().Substring(1)}{(_enddate.Day + 100).ToString().Substring(1)}"; // changePresDTP 是用AutoIT VB寫成的, 功能專一是針對「處方清單備份選項」的起迄日 [NAME:dtpSDate], [NAME:dtpEDate] // 只有一個參數, 格式為YYYYMMDDYYYYMMDD, 前面8碼是起始日, 後面8碼是結束日 string Execution = $"C:\\vpn\\exe\\changePresDTP.exe {BeginDate}{EndDate}"; AutoItX.Run(Execution, @"C:\vpn\exe\"); // 檢查XML做好了嗎? do { // log.Info(" Wait for xml to build."); // 好多紀錄啊, 大約4.9 秒 Thread.Sleep(100); } while (!System.IO.File.Exists(output)); // XML好了就把頁面關掉 AutoItX.Sleep(500); AutoItX.ControlClick("處方清單備份選項", "", "[NAME:Cancel_Button]"); AutoItX.Sleep(100); AutoItX.ControlClick("處方清單", "", "[NAME:BtnEXIT]"); #endregion Producing XML OPDconvert o = new OPDconvert(output); o.Transform(); log.Info(" End Convert."); }