Example #1
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);
        }
Example #2
0
 private void clearText(Hwnd item)
 {
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
     item.SendMessage(0x0102, '\b', 0);
 }