Click to See Complete Forum and Search --> : Query on axWebBrowser1.Navigate2


wisebulls
August 13th, 2008, 08:59 AM
I have a code that navigates to a particular site's login page, enters the user id and password, and gets forwarded to the site's home page. On landing in the home page I want to set focus of the cursor on a particular web page element called "scrip". How do I do this?

My existing code is as follows:

<CODE>

static void Main()
{
Application.Run(new MainForm());
}

private void FrmMain_Load(object sender, System.EventArgs e)
{
object loc = "https://testsite.com/login.asp";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref null_obj_str, ref null_obj_str);
}


private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
switch(Task)
{

// Here the login page gets displayed, and the login id and password is entered, and the submit button is clicked
case 1:

HTMLDocument myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument) axWebBrowser1.Document;

HTMLInputElement ologinid = (HTMLInputElement)myDoc.all.item("loginid", 0);

ologinid.value = "mylogin";

HTMLInputElement opwd = (HTMLInputElement)myDoc.all.item("brpwd", 0);

opwd.value = "mypwd";

HTMLInputElement npwd = (HTMLInputElement)myDoc.all.item("brpwd", 0);
npwd.focus();

SendKeys.Send("{Enter}");

// At this stage the home page gets displayed. Here I want to focus on element called scrip

HTMLInputElement oscrip = (HTMLInputElement)myDoc.all.item("scrip", 0);

oscrip.focus();

Task++;

break;



}
}


}

</CODE>

The code works perfectly fine till navigating to the home page, but the "scrip" element is not getting focussed.

Anybody can help?