ユーザー ID とパスワードのテキスト ボックスを提供するc# Windows アプリケーションを作成しました。送信ボタンをクリックすると、webbrowser コンポーネントを使用して www.ebay.com に eBay アカウントが自動的にログインします。入力したユーザー名とパスワードが正しければ、ログインは簡単そうです。そして今、あなたの親切な助けで私が達成したいことは:
ユーザーが Windows アプリケーションで間違ったユーザー名またはパスワードを入力するたびに、ユーザー名とパスワードが正しくないことがメッセージ ボックスに通知されます。そして、ウェブサイトへのログインに失敗したこと。
WebBrowser のイベント DocumentComplete のコードは次のとおりです。
//webTest is the name of my web browser
private void webTest_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//boolean login variable checks if the button login was clicked.
if (login == true)
{
//checks if the url is on the login page of eBay.
if (webTest.Url.AbsoluteUri == loginPage)
{
HtmlDocument doc = webTest.Document;
HtmlElement username = doc.GetElementById("userid");
HtmlElement password = doc.GetElementById("pass");
HtmlElement submit = doc.GetElementById("but_sgnBt");
username.SetAttribute("value", txtUser.Text);
password.SetAttribute("value", txtPassword.Text);
submit.InvokeMember("click");
login = false;
}
//else the webbrowser webtest will navigate to the login page,
else
webTest.Navigate(loginPage);
}
}
返信ありがとうございます。神が c# を祝福しますように!