I have created a c# windows application that have provided text box for user id and password and upon clicking submit button it will automatically log-in an eBay account to http://www.ebay.com using webbrowser component. Logging in seems to be easy if the inputted username and password was correct. And now what i want to accomplish with your kind help is:
Every time the user inputs a wrong username or password on the windows application a message box will notify the user that the username and password was incorrect. And that the logging in to the website was unsuccessful.
Here is my code for WebBrowser’s event 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);
}
}
Thank you for all the reply i really appreciate it. May God Bless c#!
Since
webTest_DocumentCompletedwill be called whenever a page is fully loaded, you should be able to detect if you were redirected from the login page to another page. For instance, the login page for eBay UK is located on the domain https://signin.ebay.co.uk/. A successful login transfers me to http://my.ebay.co.uk/ instead.You could check for this transfer in the
webTest_DocumentCompletedmethod. If it did happen, you were logged in. If not, you were not logged in (and can show a message box to alert the user).