0
Reply

Auto login into website in c# console through UI front end

anuj singh

anuj singh

Dec 23 2015 2:15 AM
660

1- I want to browse URL and when it navigate any web browser(IE,Firefox) should open then wait for page fully loaded.

2-fill all the required entries like username ans password and then click o login button here also should wait until home page fully loaded.

3-then want to go in next tab of open website. i have not write full code,here is only login code and i am getting error to run while loop which is going in infinite.


class Program {
 static WebBrowser wb = new WebBrowser();
 [STAThread]
public static void Main(string[] args)
 { string url = "***";
 wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb
.Visible = true;
wb
.ScrollBarsEnabled = false;
wb
.ScriptErrorsSuppressed = true;
wb
.Navigate(url,true);//open the url but not opening no document are loading while loop is working in infinite loop//please help.
while
(wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } }
static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 { if (wb.Url.ToString().IndexOf("loginscreen.aspx") > -1) {
wb
.Document.GetElementById("ContentPlaceHolderLoginScreen_loginControl_UserName").SetAttribute("value", "***");
wb
.Document.GetElementById("ContentPlaceHolderLoginScreen_loginControl_Password").SetAttribute("value", "****");
wb
.Document.GetElementById("ContentPlaceHolderLoginScreen_loginControl_LoginButton").InvokeMember("click");
\\
* want to wait for page load after firing click event//
 } else { Console.WriteLine("Not Login"); } }


Next Recommended Forum