r r

r r

  • NA
  • 4
  • 0

urgent need to give to client on tuesday

Jan 20 2007 6:25 AM
Hi all

Please help me with the follwing issue of web browser.
My current project is desktop application using msaccess and C# (.net2.0)
What i need to do is :
1)load a site into the webbrowser ,
2)log into the system programmatically,
3)run a loop and get 1 by 1 ID from database and place this ID in the webbrowser loaded page programatically,
4)fire an click event,
5)get the results page in web browser ,
6)read first 5 records and save them in the database.
The problem i am facing is that i want to keep the result page for each ID on the web browser for some time(i.e. till i grab the record) and then l want the web browser to go to 2nd record.
I have tried using webbrowser.ISBusy event and readystate but i am not able to hold the web browser ....the loop runs so fast that it grabs the result only for the last record which stays on the web browser because my grabbing data function executes before the entire page gets loaded.

Here is my code:

#region "Declaration of All variables And Objects"

SHDocVw.InternetExplorerClass Repoie,Fordie;

SHDocVw.WebBrowser Repowb,Fordwb;

IHTMLElementCollection ALLHTMLEle;

HtmlElementCollection elems;

HtmlDocument HTMLDoc;

IHTMLElement Repo_HTMLEle,Repo_DDHTMLEle,HTMLEle,Ford_htmlele;

IHTMLInputElement Ford_Cook;

string Str, RepoLocation,partno;

string[] splitpartno;

#endregion

#region "Waiting For the Browser to load properly"

public void WaitForBrowserToLoad(SHDocVw.InternetExplorerClass IE, WebBrowser WB, IHTMLElementCollection HTMLColl, IHTMLElement HTMLEle, string WhichBrowser, string CurrentLocation )

{

//Wait till the Object of Internet explorer And Web Browser have done their job

if (CurrentLocation != "")

{

while (WB.Url.AbsoluteUri.ToString().ToLower() == CurrentLocation.ToString().ToLower())

{

Cursor.Current = Cursors.WaitCursor; //Turn the Arrow pointer to the time glass

}

}

while (WB.IsBusy)

{

Cursor.Current = Cursors.WaitCursor; //Turn the Arrow pointer to the time glass

}

Cursor.Current = Cursors.Default; //Turn the Arrow pointer to the time glass 'Turn the Arrow pointer to the default

//End of Waiting till the Object of Internet explorer And Web Browser have done their job

if (HTMLColl != null)

{

HTMLColl.Equals(null);//Setting nothing to the HTMLElement

}

if (HTMLEle != null)

{

HTMLEle.Equals(null); //Setting nothing to the HTMLElementCollection

}

}

#endregion

#region Automatically Navigating through the Web Pages by putting the values in text fields and clicking on button

public void GoToTheDesitinationPage(WebBrowser WB,string TagSearch ,string UsrTextFldName , string PssTextFldName , string UsrTextFldVal , string PssTextFldVal , string ImageClick , string ButtonClick , string LinkClick , string WhichBrowser )

{

HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("input");

foreach (HtmlElement HTMLEl in elems)

{

//Putting the values in the text field.

if (UsrTextFldVal != "" || PssTextFldVal != "")

{

if (HTMLEl.GetAttribute("name") != null)

{

Str = HTMLEl.GetAttribute("name").ToString();

if (Str == UsrTextFldName)

{

HTMLEl.SetAttribute("value", UsrTextFldVal);

}

if (Str == PssTextFldName)

{

HTMLEl.SetAttribute("value", PssTextFldVal);

}

}

}

 

//Clicking on the image (button)

if (ImageClick != "")

{

if (HTMLEl.GetAttribute("Type").ToString() != "")

{

if ((HTMLEl.GetAttribute("name").ToString() == ImageClick.ToString()) || (HTMLEl.OuterHtml == ImageClick.ToString()))

{

HTMLEl.InvokeMember("Click");

goto exitfo;

}

}

}

//End of Clicking on the image (button)

}

exitfo:

string str = "1";

}

#endregion

private void Form1_Load(object sender, EventArgs e)

{

webBrowser1.Navigate(https://www.xyz.com);

partno = "CP12,312XCI,M3000,451";

splitpartno = partno.Split(",".ToCharArray());

}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

Cursor.Current = Cursors.Default;

if (webBrowser1.Document != null)

{

GoToTheDesitinationPage(webBrowser1, "input", "userName", "password", "rl", "r", "login", "", "", "Repo");

RepoLocation = webBrowser1.Url.AbsolutePath.ToString();

System.Threading.Thread.Sleep(3000);

if (RepoLocation.ToLower() == login_in.do")

{

for (int i = 0; i <= splitpartno.Length - 1; i++)

{

textBox1.Text = splitpartno[i].ToString();

if (i == 0)

{

GoToTheDesitinationPage(webBrowser1, "input", "query", "", splitpartno[i].ToString(), "", "<INPUT type=image height=22 alt=\"Find It!\" width=65 src=\"/images/advrewrite/find_it.gif\" value=\"\" border=0>", "", "", "Repo");

}

else

{

GoToTheDesitinationPage(webBrowser1, "input", "query", "", splitpartno[i].ToString(), "", "find", "", "", "Repo");

}

WaitForBrowserToLoad(Repoie, webBrowser1, ALLHTMLEle, HTMLEle, "Repo","");

System.Threading.Thread.Sleep(10000);

MessageBox.Show(splitpartno[i].ToString());

}

}

}

}

private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)

{

Cursor.Current = Cursors.WaitCursor;

}