I'm trying to programmatically go to the web site of a large cell phone company (rhymes with Murizon) and enter my account's username, secret answer, and password. This is being done in a simple Winform with a WebBrowser control and a few buttons.
The way this site works is that it first prompts for the user, then the secret question, then the password. I've dumbed it down to the point where each answer is entered by a different button. I'm using the following code to enter each of the three prompts:
private void button2_Click(object sender, EventArgs e)
{
var browser = this.webBrowser1;
var txt = browser.Document.GetElementById("IDToken1");
if (txt != null)
{
txt.SetAttribute("Value", Constants.SecretAnswer);
var btnLogin = browser.Document.GetElementById("signIn");
btnLogin.InvokeMember("click");
}
}
This works fine for the username prompt and the password prompt. But it does not seem to work for the secret question prompt ("what is your first pet's name", etc). I get the error "...Data may be missing or may be entered in an invalid format." The answer that the code is entering is the correct answer.
I've tried using "SendKeys.Send()", as well as setting the "txt.InnerText" property. I've also tried setting the focus on it before setting the value. I also tried invoking a "click" on it. I get the same error each time.
The form html source looks very similar in all three cases. There is some JS that is run in the "onfocus", but that same JS is on the other two prompts, so I'm assuming that if it works for one it should work for all three.
I know I'm getting the secret question prompt because it doesn't recognize the WebBrowser control the first time, and I know that I can make it remember and not get the secret question prompt again, but I'd like to figure out why this specific form is not recognizing the value I'm setting in case I run into this in the future. Is there anything that I'm missing?
Aucun commentaire:
Enregistrer un commentaire