TextBox.Text (password field) throws System.InvalidOperationException?

Dec 22, 2008 at 6:52 PM
My test is trying to read the text in a TextBox.  If the C#-not-White TextBox has set PasswordChar, then White TextBox.Text throws a "Operation is not valid due to the current state of the object" System.InvalidOperationException.  Why does White throw this exception?  Is there any way for White to tell if a TextBox has PasswordChar set or not?

One of our requirements in our Login form is to have a "show password" toggle that will allow the password field to show the password instead of asterisks.  (Yeah, I think it's silly too, but that's what the customer wants.)  So I'd like to have something like the following:

TextBox usernameBox = window.Get<TextBox>("txtAccountID");
TextBox passwordBox = window.Get<TextBox>("txtPassword");
CheckBox chkShowPwd = window.Get<CheckBox>("chkShowPwd");

usernameBox.Text = "ChuckNorris";
passwordBox.Text = "ChucksPassword"; // password field is asterisks

Assert.Equals("**************", passwordBox.Text); // causes exception

chkShowPwd.Select(); // transforms asterisks to plaintext

Assert.Equals("ChucksPassword", passwordBox.Text); // also causes exception


Jan 10, 2009 at 10:37 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jan 10, 2009 at 10:46 AM
The reason you are getting this exception is because password field's text cannot be retrieved.
I have registered it as a bug.
Although, the fix would be to throw clear exception stating the reason than what you are getting.