Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ovide CodeHi All,
I am developing a C# windows application where I am using windows web browser control to automated a web application. I am using webBrowser1_DocumentCompleted event to download file it is working but at the end it popup windows message box for that I am using timer event with sendKey so download is happening but after that it goes to other pages not in home page.

What should I do Please advice.

Below I provide Code

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if ((bFirstTime == true) && (e.Url.ToString().Contains(sPageLogin))) //only first time
{
toolStripTextBox1.Text = webBrowser1.Url.ToString();
bFirstTime = false;
HtmlElement heElement;
HtmlDocument doc = webBrowser1.Document;
HtmlElement userName = doc.GetElementById("userName");
HtmlElement password = doc.GetElementById("password");
if (userName != null)
userName.SetAttribute("value", "hello");
if (password != null)
password.SetAttribute("value", "thnaks");
System.Threading.Thread.Sleep(2000);

foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
{
if (el.Name == "login" && el.OuterHtml.Contains("javascript:doSubmit()"))
{
el.InvokeMember("Click");
System.Threading.Thread.Sleep(2000);
}
}

}
else
{
if ((e.Url.ToString().Contains("/1/roleDefine.do")) || (e.Url.ToString().Contains("/abc/xyz/mno/1/retrieveHomePage.do")))
{ //https://applications.abc.com/xyz/mno/mtnl/1/roleDefine.do
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("a"))
{
if (el.OuterHtml.Contains("/tdct/prod/wlbx/1/D624D669/en/images/buttons/home_images.jpg"))
{
el.InvokeMember("Click");
}
}

}
}
else if ((e.Url.ToString().Contains("/tdct/prod/wlbx/1/transaction/searchCheck.do")))
{
//httpshttps://applications.abc.com/xyz/mno/mtnl/1/searchCheck.do
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("a"))
{
if (el.OuterHtml.Contains("/tdct/prod/wlbx/common/images/icons/save.gif"))
{
el.InvokeMember("Click");
}
}
isHasAttachment = true;
if (isHasAttachment)
{
SendKeys.Send("{Enter}");


//System.Threading.Thread.Sleep(5000);

System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 15000;
t.Tick += new EventHandler(timer_Tick);
t.Start();
}
}

void timer_Tick(object sender, EventArgs e)
{
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
SendKeys.Send("{ENTER}");

}
}
Thanks to All

What I have tried:

problem with C# windows application web browser control to automated a web application
Posted
Updated 27-Jun-16 21:16pm
v2
Comments
[no name] 28-Jun-16 1:48am    
Code please....only description in weird english is very..very..very.. difficult to understand...
OriginalGriff 28-Jun-16 2:30am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
jayveebishie 28-Jun-16 2:35am    
Do you want to open your home page after download is finish? Have you tried using the WebBrowser.Navigate method?
IndrajitDasgupat 28-Jun-16 3:01am    
Yes Sir I want to open homepage after download
jayveebishie 28-Jun-16 3:08am    
webBrowser1.Navigate("YOUR HOMEPAGE URL HERE");

1 solution

whenever you want to change the page, use
webBrowser1.Navigate ("URL");
 
Share this answer
 
v2
Comments
IndrajitDasgupat 28-Jun-16 3:33am    
should I put webBrowser1.Navigate("YOUR HOMEPAGE URL HERE") inside the timer_Tick function
Kiran Vaidyanathan 28-Jun-16 22:54pm    
Yes under the timer tick function.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900