/// <inheritdoc /> public override bool HandleDialog(Window window) { if (CanHandleDialog(window)) { window.ToFront(); window.SetActivate(); var inputBoxHwnd = new Hwnd(NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit")); if (inputBoxHwnd.hwnd == IntPtr.Zero) { return(false); } if (_cancel) { window.ForceClose(); } else { inputBoxHwnd.SetFocus(); inputBoxHwnd.SendString(_input); var okButton = new WinButton(1, window.Hwnd); okButton.Click(); } return(true); } return(false); }
public override bool HandleDialog(Window window) { if (IsPromptDialog(window)) { window.ToFront(); window.SetActivate(); Window inputBox = new Window(NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit")); if (inputBox.Hwnd != IntPtr.Zero) { if (_cancel) { window.ForceClose(); } else { NativeMethods.SetActiveWindow(inputBox.Hwnd); System.Windows.Forms.SendKeys.SendWait(_input); System.Windows.Forms.SendKeys.SendWait("{ENTER}"); } return(true); } } return(false); }
public override bool HandleDialog(Window window) { if (IsPromptDialog(window)) { window.ToFront(); window.SetActivate(); Window inputBox = new Window(NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit")); if (inputBox.Hwnd != IntPtr.Zero) { if (_cancel) { window.ForceClose(); } else { NativeMethods.SetActiveWindow(inputBox.Hwnd); System.Windows.Forms.SendKeys.SendWait(_input); System.Windows.Forms.SendKeys.SendWait("{ENTER}"); } return true; } } return false; }
/// <summary> /// If the window is a dialog and visible, it will be passed to /// the registered dialog handlers. I none if these can handle /// it, it will be closed if <see cref="CloseUnhandledDialogs"/> /// is <c>true</c>. /// </summary> /// <param name="window">The window.</param> public void HandleWindow(Window window) { if (!window.IsDialog()) { return; } if (!HasDialogSameProcessNameAsBrowserWindow(window)) { return; } if (!window.Visible) { return; } int topProcessID = window.ToplevelWindow.ProcessID; if ((TopWindow.ProcessID != topProcessID) && (MainWindow.ProcessID != topProcessID)) { return; } // This is needed otherwise the window Style will return a "wrong" result. WaitUntilVisibleOrTimeOut(window); // Lock the thread and see if a handler will handle // this dialog window lock (this) { foreach (var dialogHandler in _handlers) { try { if (dialogHandler.CanHandleDialog(window, MainWindow.Hwnd)) { if (dialogHandler.HandleDialog(window)) { return; } } } catch (Exception e) { LastException = e; Logger.LogAction((LogFunction log) => { log("Exception was thrown while DialogWatcher called HandleDialog: {0}", e.ToString()); }); } } // If no handler handled the dialog, see if the dialog // should be closed automatically. if (!CloseUnhandledDialogs) { return; } Logger.LogAction((LogFunction log) => { log("Auto closing dialog with title: '{0}', text: {1}, style: ", window.Title, window.Message, window.StyleInHex); }); window.ForceClose(); } }
public void Close() { Window dialog = new Window(hwnd); if (dialog.Visible) { dialog.ForceClose(); } base.Dispose(true); }
public override bool HandleDialog(Window window) { var handle = GetMessageBoxHandle(window); if (handle != IntPtr.Zero) { alertQueue.Enqueue(NativeMethods.GetWindowText(handle)); window.ForceClose(); return(true); } return(false); }
public void CloseDialog() { if (msg == "The webpage you are viewing is trying to close the tab.\n\nDo you want to close this tab?" || msg == "The webpage you are viewing is trying to close the window.\n\nDo you want to close this window?") // It does not seem as though this dialog is properly handled, resulting in an uncaught exception { WinButton yesButton = new WinButton(6, _window.Hwnd); // Not sure if ID will always be 6, but with the current example it is if (yesButton.Exists()) { yesButton.Click(); } } if (_window != null) { _window.ForceClose(); } }
public override bool HandleDialog(Window window) { // See if the dialog has a static control with a controlID // of 0xFFFF. This is unique for alert and confirm dialogboxes. IntPtr handle = NativeMethods.GetDlgItem(window.Hwnd, 0xFFFF); if (handle != IntPtr.Zero) { alertQueue.Enqueue(NativeMethods.GetWindowText(handle)); window.ForceClose(); return(true); } return(false); }
/// <summary> /// If the window is a dialog and visible, it will be passed to /// the registered dialog handlers. I none if these can handle /// it, it will be closed if <see cref="CloseUnhandledDialogs"/> /// is <c>true</c>. /// </summary> /// <param name="window">The window.</param> public void HandleWindow(Window window) { if (window.IsDialog()) { WaitUntilVisibleOrTimeOut(window); // Lock the thread and see if a handler will handle // this dialog window lock (this) { foreach (IDialogHandler dialogHandler in handlers) { try { if (dialogHandler.HandleDialog(window)) { return; } } catch (Exception e) { lastException = e; Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:"); Logger.LogAction(e.ToString()); } } // If no handler handled the dialog, see if the dialog // should be closed automatically. if (CloseUnhandledDialogs) { Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title); window.ForceClose(); } } } }
public override bool HandleDialog(Window window) { // See if the dialog has a static control with a controlID // of 0xFFFF. This is unique for alert and confirm dialogboxes. IntPtr handle = NativeMethods.GetDlgItem(window.Hwnd, 0xFFFF); if (handle != IntPtr.Zero) { alertQueue.Enqueue(NativeMethods.GetWindowText(handle)); window.ForceClose(); return true; } return false; }
/// <summary> /// If the window is a dialog and visible, it will be passed to /// the registered dialog handlers. I none if these can handle /// it, it will be closed if <see cref="CloseUnhandledDialogs"/> /// is <c>true</c>. /// </summary> /// <param name="window">The window.</param> public void HandleWindow(Window window) { if (!window.IsDialog()) { return; } if (Process.GetProcessById(window.ProcessID).ProcessName != "iexplore") { return; } if (string.IsNullOrWhiteSpace(window.Title)) { return; } if (Count > 0) { // This is needed otherwise the window Style will return a "wrong" result. if (CloseUnhandledDialogs) { WaitUntilVisibleOrTimeOut(window); } //Logger.LogDebug("Find dialog " + window.Title); // Lock the thread and see if a handler will handle // this dialog window lock (this) { foreach (var dialogHandler in _handlers) { //Logger.LogDebug(dialogHandler.GetType().Name); try { if (dialogHandler.CanHandleDialog(window, MainWindowHwnd)) { Logger.LogAction("Handle dialog"); if (dialogHandler.HandleDialog(window)) { return; } } } catch (Exception e) { LastException = e; Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:"); Logger.LogAction(e.ToString()); } } } } // If no handler handled the dialog, see if the dialog // should be closed automatically. if (!CloseUnhandledDialogs) { return; } Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title); window.ForceClose(); }
/// <summary> /// If the window is a dialog and visible, it will be passed to /// the registered dialog handlers. I none if these can handle /// it, it will be closed if <see cref="CloseUnhandledDialogs"/> /// is <c>true</c>. /// </summary> /// <param name="window">The window.</param> public void HandleWindow(Window window) { if (window.IsDialog()) { WaitUntilVisibleOrTimeOut(window); // Lock the thread and see if a handler will handle // this dialog window lock (this) { foreach (IDialogHandler dialogHandler in handlers) { try { if (dialogHandler.HandleDialog(window)) return; } catch (Exception e) { lastException = e; Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog:"); Logger.LogAction(e.ToString()); } } // If no handler handled the dialog, see if the dialog // should be closed automatically. if (CloseUnhandledDialogs) { Logger.LogAction("Auto closing dialog with title '{0}'.", window.Title); window.ForceClose(); } } } }