/// <summary> /// Enter input and then click ok button /// </summary> /// <param name="username">Username for dialog</param> /// <param name="password">Password for dialog</param> /// <returns></returns> public bool EnterInput(string username, string password) { //webbrowserhost is the parent for security dialog NativeWindowCalls.SetForegroundWindow(SecurityWindow); // #32770 for security dialog if (securityWindow != IntPtr.Zero) { // username field may not be as edit field ( If dialog is remembering the credentials, username is text field IntPtr usernameWndPtr = NativeWindowCalls.GetEmptyUsernameField(SecurityWindow); if (usernameWndPtr != IntPtr.Zero) { string titleText = NativeWindowCalls.GetWindowText(usernameWndPtr); NativeWindowCalls.SetFocus(usernameWndPtr); NativeWindowCalls.SetText(usernameWndPtr, username); titleText = NativeWindowCalls.GetWindowText(usernameWndPtr); if (titleText != username) { return(false); // it did not enter } } // Password field IntPtr childWndPtr = NativeWindowCalls.GetEmptyPasswordField(SecurityWindow); if (childWndPtr != IntPtr.Zero) { NativeWindowCalls.SetFocus(childWndPtr); NativeWindowCalls.SetText(childWndPtr, password); // Verify to make sure it is set on this control string passwordText = NativeWindowCalls.GetWindowText(childWndPtr); if (passwordText == password) { // Ok button's classname in this dialog is "Button" // there are many other buttons that are not visible to user in this dialog IntPtr okBtn = NativeWindowCalls.GetChildWindowHwnd(SecurityWindow, "Button", "Ok"); return(this.ClickOkButton(okBtn)); } } } return(false); }