/// <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
        /// <summary>
        /// Handles the logon dialog by filling in the username and password.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        public override bool HandleDialog(WatiN.Core.Native.Windows.Window window)
        {
            if (runonce)
            {
                return(false);
            }

            if (CanHandleDialog(window))
            {
                runonce = true;
                // Find Handle of the "Frame" and then the combo username entry box inside the frame
                var systemCredentialsHwnd = GetSystemCredentialsHwnd(window);

                SetActiveWindow(window.Hwnd);
                Thread.Sleep(1000);

                SetForegroundWindow(window.Hwnd);
                Thread.Sleep(1000);

                var windowEnumarator = new WindowsEnumerator();
                var all = windowEnumarator.GetChildWindows(systemCredentialsHwnd);
                // Find input fields
                var edits = windowEnumarator.GetChildWindows(systemCredentialsHwnd, "Edit");

                Thread.Sleep(2000);
                // Enter userName
                var hwnd = new Hwnd(edits[0].Hwnd);
                hwnd.SetFocus();
                clearText(hwnd);
                hwnd.SendString(userName);

                hwnd.SendMessage(0x0102, '\t', 0);
                hwnd = null;
                Thread.Sleep(2000);

                // Enter password
                hwnd = new Hwnd(edits[1].Hwnd);
                hwnd.SetFocus();
                clearText(hwnd);
                hwnd.SendString(password);


                // Click OK button
                var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
                if (windowButton != null)
                {
                    new WinButton(windowButton.Hwnd).Click();
                }
                //new WinButton(1, window.Hwnd).Click();
                //new WinButton(0, window.Hwnd).Click();

                return(true);
            }

            return(false);
        }
Exemple #3
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();
        }
Exemple #4
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 #5
0
        /// <summary>
        /// Handles the logon dialog by filling in the username and password.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        public override bool HandleDialog(Window window)
        {
            if (CanHandleDialog(window))
            {
                // Find Handle of the "Frame" and then the combo username entry box inside the frame
                var systemCredentialsHwnd = GetSystemCredentialsHwnd(window);

                NativeMethods.SetActiveWindow(window.Hwnd);
                Thread.Sleep(50);

                NativeMethods.SetForegroundWindow(window.Hwnd);
                Thread.Sleep(50);

                var windowEnumarator = new WindowsEnumerator();

                // Find input fields
                var edits = windowEnumarator.GetChildWindows(systemCredentialsHwnd, "Edit");

                // Enter userName
                var hwnd = new Hwnd(edits[0].Hwnd);
                hwnd.SetFocus();
                hwnd.SendString(userName);

                // Enter password
                hwnd = new Hwnd(edits[1].Hwnd);
                hwnd.SetFocus();
                hwnd.SendString(password);

                // Click OK button
                new WinButton(1, window.Hwnd).Click();

                return(true);
            }

            return(false);
        }