/// <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);
        }
Exemple #2
0
        private void HandleFileSaveDialog(Window window)
        {
            var fileNameHandle = NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit");
            var fileNameHwnd   = new Hwnd(fileNameHandle);

            fileNameHwnd.SetFocus();
            fileNameHwnd.SendString(saveAsFilename);

            var openButton = new WinButton(1, window.Hwnd);

            openButton.Click();
        }
        public override bool HandleDialog(Window window)
        {
            if (CanHandleDialog(window))
            {
                var buttonId = _clickOnOK ? okButtonId : cancelButtonId;

                var button = new WinButton(buttonId, window.Hwnd);
                button.Click();

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Handles the dialog if the <paramref name="window" /> is a
        /// security alert dialog.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        public override bool HandleDialog(Window window)
        {
            if (CanHandleDialog(window))
            {
                NativeMethods.SetForegroundWindow(window.Hwnd);
                NativeMethods.SetActiveWindow(window.Hwnd);

                var buttonOk = new WinButton(1, window.Hwnd);
                buttonOk.Click();

                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();
     }
 }
Exemple #6
0
        /// <summary>
        /// Handles the File upload dialog.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        public override bool HandleDialog(Window window)
        {
            if (CanHandleDialog(window))
            {
                var fileNameHandle = NativeMethods.GetChildWindowHwnd(window.Hwnd, "Edit");
                var fileNameHwnd   = new Hwnd(fileNameHandle);

                fileNameHwnd.SetFocus();
                fileNameHwnd.SendString(fileName);

                var openButton = new WinButton(1, window.Hwnd);
                openButton.Click();

                return(true);
            }

            return(false);
        }
Exemple #7
0
        private bool HandledDownloadProgressDialog(Window window)
        {
            if (IsDownloadProgressDialog(window))
            {
                DownloadProgressDialog = window;

                var openOrRun = new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    var close = new WinButton(2, new Hwnd(window.Hwnd));
                    close.Click();

                    var actionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(5));
                    actionUntilTimeOut.Try(() => window.Exists());

                    // TODO: What to do if the window doesn't close after timeout?
                }

                return(true);
            }
            return(false);
        }
Exemple #8
0
        /// <summary>
        /// Handles the dialogs to download (and save) a file
        /// Mainly used internally by WatiN.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        public override bool HandleDialog(Window window)
        {
            // This if handles the File download dialog
            if (!HasHandledFileDownloadDialog && IsFileDownloadDialog(window))
            {
                window.ToFront();
                window.SetActivate();

                DownloadProgressDialog = new Window(window.ParentHwnd);

                WinButton btn = GetButtonToPress(window);
                btn.Click();

                hasHandledFileDownloadDialog = !Exists(window);

                if (HasHandledFileDownloadDialog)
                {
                    Logger.LogAction("Download started at " + DateTime.Now.ToLongTimeString());
                    Logger.LogAction("Clicked " + _optionEnum.ToString());
                }

                return(true);
            }

            // This if handles the download progress dialog
            if (IsDownloadProgressDialog(window))
            {
                DownloadProgressDialog = window;

                WinButton openOrRun = new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    WinButton close = new WinButton(2, new Hwnd(window.Hwnd));

                    close.Click();

                    SimpleTimer timer = new SimpleTimer(5);
                    while (!timer.Elapsed && window.Exists())
                    {
                        Thread.Sleep(200);
                    }
                }

                return(true);
            }

            // This if handles the File save as dialog
            if (IsFileSaveDialog(window))
            {
                Logger.LogAction("Saving Download file as " + saveAsFilename);

                DownloadProgressDialog = new Window(window.ParentHwnd);

                HandleFileSaveDialog(window);

                return(true);
            }

            // Window is not a dialog this handler can handle.
            return(false);
        }
		/// <summary>
		/// Handles the dialogs to download (and save) a file
		/// Mainly used internally by WatiN.
		/// </summary>
		/// <param name="window">The window.</param>
		/// <returns></returns>
		public override bool HandleDialog(Window window)
		{
			// This if handles the File download dialog
			if (!HasHandledFileDownloadDialog && IsFileDownloadDialog(window))
			{
				window.ToFront();
				window.SetActivate();

				DownloadProgressDialog = new Window(window.ParentHwnd);

				WinButton btn = GetButtonToPress(window);
				btn.Click();

				hasHandledFileDownloadDialog = !Exists(window);

				if (HasHandledFileDownloadDialog)
				{
					Logger.LogAction("Download started at " + DateTime.Now.ToLongTimeString());
					Logger.LogAction("Clicked " + _optionEnum.ToString());
				}

				return true;
			}

			// This if handles the download progress dialog
			if (IsDownloadProgressDialog(window))
			{
				DownloadProgressDialog = window;

                WinButton openOrRun= new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    WinButton close = new WinButton(2, new Hwnd(window.Hwnd));

                    close.Click();
                    
                    SimpleTimer timer = new SimpleTimer(5);
                    while (!timer.Elapsed && window.Exists())
                    {
                        Thread.Sleep(200);
                    }
                }

				return true;
			}

			// This if handles the File save as dialog
			if (IsFileSaveDialog(window))
			{
				Logger.LogAction("Saving Download file as " + saveAsFilename);

				DownloadProgressDialog = new Window(window.ParentHwnd);

				HandleFileSaveDialog(window);

				return true;
			}

			// Window is not a dialog this handler can handle.
			return false;
		}