hi everybody,
i am a freshly formed in proffessional programming in the .net c#, VB, and Asp.net platform. For a new personal project, i am trying to find a solution to sign in to a site automatically.
i started inserting a webBrowser in the windows form, charged the url which contains the sign in part from the main page.. ie. the main page was
<<snip>>
and the one i extracted from the html source is this
<<snip>>
I was able to successfully insert a username and password to the textboxes through
webBrowser.getelementByID("name of the control").Setattribute("value", "username")
webBrowser.getelementByID("name of the control").Setattribute("value", "username")
My problem is when i want to submit i am not able to find the control (to execute the click on thesubmit button) through getElementById because the submit button has no name!
so how should i execute the click (as if it was done manually by a mouse click)
i have used a code to give the submit button, a name trough inserting html codes with the syntax
webBrowser.DocumentText= <the sourcecode i have modofied from the original sorce code (giving name to the submit button)>
i will post it below
public void btnGetText_Click(object sender, EventArgs e)
{
//giving the username and password to the html textboxes
webBrowser1.Document.GetElementById("user").SetAttribute("value", "<<snip>>");
webBrowser1.Document.GetElementById("pass").SetAttribute("value", "<<snip>>");
//redifining the html which is loaded in the weBrowser control
webBrowser1.DocumentText = "<html> " +
" <head> " +
/*<!-- Here i added a javascript function which auto submits this page With a time delay of ten seconds"
(the time for the program to insert the user name and password before the sumbission) --> */
"<script type=\"text/javascript\">" +
"setTimeout(\"document.forms[0].submit()\", 10000);" +
"</script>" +
"</head>" +
" <style type=\"text/css\"> " +
" html, body { padding: 0; margin: 0; }" +
" table.footerlogin, table.footerlogin tr, table.footerlogin tr td" +
" {" +
" font-size: 11px;" +
" font-family: Arial, Verdana, sans-serif;" +
" color: #000000;" +
" }" +
" input {" +
" font-size: 10px;" +
" }" +
" input.flinput {" +
" border: 1px solid black;" +
" font-size: 11px;" +
" width: 100px;" +
" }" +
" body" +
" {" +
" /* background : #FCED4A url('../images/iframe_bc.jpg') repeat-x ; */ " +
" }" +
" label { font-weight: bold; }" +
" </style> " +
" </head> " +
" <body style=\"padding: 0px; margin-top: 10px;\"> " +
" <form autocomplete=\"off\" action=\"index.php?part=tplogin\" name=\"loginpanel\" target=\"_top\" method=\"post\"> " +
" <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"footerlogin\"> " +
" <tr> " +
" <td colspan=\"3\">" +
" <label></label> " +
" </td> " +
" </tr> " +
" <tr> " +
" <td> " +
" <label>Username</label> " +
" </td> " +
" <td> " +
// <!-- here i have given the textbox, a value -->
" <input type=\"text\" name=\"user\" value=\"<<snip>>_in\" size=\"20\" class=\"flinput\" />" +
" </td> " +
" <td> " +
" " +
" </td> " +
" </tr> " +
" <tr> " +
" <td> " +
" <label>Password</label> " +
" </td> " +
" <td> " +
// <!-- here i have given the textbox for password, a value -->
" <input type=\"password\" name=\"pass\" value=\"<<snip>>\" size=\"20\" class=\"flinput\" />" +
" </td>" +
" <td> " +
// <!-- here i have given a name to the submit button, (submitButton) if somebody should ask why i had to give it a name to just submit the form, i would say it was to try to use another code whick execute the click() function in finding the button through getElementById consul the next part of code i have posted (it was the secont technique i have used but didnt work also :( ! -->
" <input type=\"submit\" value=\"signin\" name=\"submitButton\" />" +
" </td> " +
" </tr> " +
" </table> " +
" </form> " +
" </body> " +
"</html> ";
}
the second technique other than the autosubmit was as follows
private void button1_Click(object sender, EventArgs e)
{
HtmlElement el = webBrowser1.Document.All["submitButton"];
object obj = el.DomElement;
System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
mi.Invoke(obj, new object[0]);
webBrowser1.Navigate("https://www.jumblo.com/myaccount/promo.php");
}
ok now all this code works, it clicks and submits, but the website loaded in the webBrowser tells me