 |
|

|
This article is very helpful. But I have a task to login to a Siebel CRM website, navigate the website and download some reports by submitting some parameters. I need to simulate these steps. My question is can this be done from a C# application? And what libraries are required.
Pal
|
|
|
|

|
That really helped me a lot!!
Thanks for a simple explanation as well.
|
|
|
|

|
Excellent piece of code from Alexander (the Kent)
|
|
|
|

|
Very useful! Thanks Alexander, been looking for something like this for a while
Take 5
|
|
|
|

|
Hello,
Is there any way to use this in web application....I tried to use it in my web application..my target to fill a web form on another URL dynamically, but it shows "Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown asp.net" on the following line
this.axWebBrowser1.Navigate2(ref loc, ref null_obj, ref null_obj, ref null_obj_str, ref null_obj_str);
my code snippet is the following...please suggest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using MSHTML;
using System.ComponentModel;
using System.Threading;
using AxSHDocVw;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private int Task = 1; private System.ComponentModel.Container components = null;
private void InitializeComponent()
{
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)
(this.axWebBrowser1)).BeginInit();
axWebBrowser1.SuspendLayout();
this.axWebBrowser1.Anchor =
((System.Windows.Forms.AnchorStyles)
((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new System.Drawing.Point(0, 72);
this.axWebBrowser1.Size = new System.Drawing.Size(360, 232);
this.axWebBrowser1.TabIndex = 0;
}
protected void Page_Load(object sender, EventArgs e)
{
Thread webBrowseThread = new Thread(new ThreadStart(PerformWebBrowseOp));
webBrowseThread.SetApartmentState(ApartmentState.STA);
webBrowseThread.Start();
}
protected void PerformWebBrowseOp()
{
InitializeComponent();
axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(axWebBrowser1_NavigateComplete2);
object loc = "http://www.google.com/";
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_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
}
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
switch (Task)
{
case 1:
HTMLDocument myDoc = new HTMLDocumentClass();
myDoc = (HTMLDocument)axWebBrowser1.Document;
HTMLInputElement otxtSearchBox = (HTMLInputElement)myDoc.all.item("q", 0);
otxtSearchBox.value = "intel corp";
HTMLInputElement btnSearch = (HTMLInputElement)myDoc.all.item("btnI", 0);
btnSearch.click();
Task++;
break;
case 2:
break;
}
}
}
Thanks - Arin
Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx
|
|
|
|
|
|

|
Hello
Thanks for your very helpfull article
Can I use your model to execute jQuery embedded in a page ?
Or is there any other way to browse a page from cSharp, detect jQuery method and call them
Or do I have to forget cSharp to do it ?
What will be the better approach
Thanks
Olivier
|
|
|
|

|
This article help me in complete one of my browser automation project.
I think very soon I will article about my project.
|
|
|
|

|
I have Button, but it haven't got name:
<button type="button" style="background:#e30613; color:#FFF; border:1px;" önclick="sendData(322, 1);">Send</button>
Now, i want to call: sendData(322, 1)
What can i do?
Please show me!
Thanks!
|
|
|
|

|
Hi,
Your sample is cool and i tried in IE7 no issue, but when moved IE8 the axBrowserControl's axBrowserControl_DocumentCompleted does not seems to fire, so i used the default WebBrowser which is in toolbox by default all the things are ok now the Documnet complete fires and so on. but i cannot seems to use the code
HTMLInputElement btnSearch =
(HTMLInputElement) myDoc.all.item("btnI", 0);
btnSearch.click();
since the HTMLInputElement is in MSHTML dll and i am not using it and cannot convert the webBrowser controls element to "HTMLInputElement" instead have to convert to "HTMLElement" but click is the issue
HtmlElement btnGo = (HtmlElement)objHTMLDoc.All["login_button_box"];
btnGo.Click(); // this is not allowed
//btnGo.RaiseEvent("click"); //tried this too have some issue
Also i am able to set the Text boxes with values but cannot seems to CLICK a button
Can you help mein this senario
Thanks in advance
When you hold a hammer, everything looks like a nail.
|
|
|
|

|
Hi,
I have a problem where the page is generated via ajax so when I try to find controls on the page the reference is null because they do not exist until AJAX creates them?
Thank
|
|
|
|

|
Hi,
I have a problem.
I want to navigate to page http://www.me.com/;
I use AxWebBrowser.
when it throw event DocumentComplete
I click continue.
now I have problem without solution :/
I fill login and pass, and click Log In
it's do nothing
---------------------------
I think it is js problem
How to solve it??
Thanks for any advise
|
|
|
|

|
I want to have a loop that loads a new page from a string array
of several website addresses.
here is where I collect the web addresses I want to load in a loop
and then load one at a time and get information off their page:
c = 0;
cc = 0;
foreach (Match match in collection)
{
GroupCollection groups = match.Groups;
strArrayWWWcargoShipNames[c] = string.Format("{1}",groups["word"].Value,groups[0].Value,groups[1].Value);
if (strArrayWWWcargoShipNames[c] != "http://www.google.com")
{
if (strArrayWWWcargoShipNames[c] != "http://www.mozilla.com")
{
if (strArrayWWWcargoShipNames[c] != "http://www.easycounter.com")
{
strArrayWWWcargoShipNamesCleaned1[cc] = strArrayWWWcargoShipNames[c];
cc++;
}
}
}
c++;
}
this doesn't work...I think I'm not handling the readystate or something:
object loc2 = strArrayWWWcargoShipNamesCleaned1[cc];
object null_obj_str2 = "";
System.Object null_obj2 = 0;
this.axWebBrowser1.Navigate2(ref loc2, ref null_obj2, ref null_obj2, ref null_obj_str2, ref null_obj_str2);
mshtml.HTMLDocumentClass doc2 = (mshtml.HTMLDocumentClass)this.axWebBrowser1.Document;
Your help is appreciated.
Thanks,
Trint
|
|
|
|

|
I have been trying to automate WebBrowser since long time and the biggest challenge to me is how to determine when navigation is completed. For simple web site, DocumentComplete event is good enough, which is very simple to do. However, for a complex web site, it is difficult to do.
Anybody have better idea?
miliu
|
|
|
|

|
Hi, guys look at this article
http://www.codeproject.com/KB/cs/automatingwebbrowsing.aspx
|
|
|
|

|
Hi,
I cant find any reference in the library which namesapce is mshtml. Please advice me how I can import this namspace to the library. Thanks.
Regards,
YB
|
|
|
|

|
i want to know how to give the value to textarea by using mshtml
|
|
|
|

|
How do i click a dynamic javascript button or object like adsense in a web page?
|
|
|
|

|
I mean to accept or cancel download automatically!
thanks
|
|
|
|

|
Friends,
I want to find the properties of HTML controls in html files. Is there any method of webbrowser control to find the properties of all HTML web controls in html page,(The html page) which is displyed in the webbrowser control ?
Thanks in Advance.
|
|
|
|

|
how do i write this in c++?
my try:
mshtml::HTMLDocument^ doc= gcnew mshtml::HTMLDocumentClass();
doc = (mshtml::HTMLDocument^) axWebBrowser1->Document;
mshtml::HTMLInputElement ^login = (mshtml::HTMLInputElement^) doc->all->item("loginname",0);
login->value= "test";
keeps the program crashin.. pls help.
|
|
|
|

|
i noticed that the control uses the default windows cookies directory to store cookies and so shares the cookies with IE. Can this directory be overridden somehow ?
|
|
|
|

|
Hello
I want to save the source of the result page(after button clicked) but I didnt find a propper way to achieve it with code
if ( ( (int)axWebBrowser1.ReadyState >= 4) & ( ! axWebBrowser1.Busy ))
{
str = new StreamWriter("C:\\saved.txt");
str.Write( myDoc.documentElement.innerHTML) ;
}
any help would be apreciated.
.
|
|
|
|

|
At the begining ,I'm sorry for my poor English...
Now I'm make a WinForm application and input the axWebBrowser in it.
then I get a program to auto fill the input box in the webpage for the page have frameset in it.
for example:
I navigate http://website/t1.htm ,it's have a frame that
<frameset name="t2" src="t2.htm">
then at the t2 document ,it contain a frame <frameset name="t3" src="t3.htm">
in t3, there have <form name="a1"><input type="textbox" name="text1" value="ok"></input></form>
========
then when I browse t1.htm ,how can I get the value of textbox named text1 in t3.htm?
best regards </frameset></frameset>
|
|
|
|

|
how do i open a herf link
thank tou
|
|
|
|

|
Hello friends , I need some help this is my requirment
I have
1)a textbox
2) a webbrowser component in my windows form
3) a aspx form
now when i execute my windows application, i will enter my aspx form address inthe text box. this aspx form will have a function which returns a string. i need to capture this string and print on my windows form(may be a lable or a message box)
how can i do that?
waiting for ur reply
with regards
harivinod
harivinod
|
|
|
|

|
You'll have to use the WebBrowser.Document.DomDocument class instead to get the MSHTML corresponding HTMLDocument object
Dim htmlDoc As HTMLDocument
Dim userBox As HTMLInputElement
Dim passBox As HTMLInputElement
htmlDoc = New HTMLDocumentClass()
htmlDoc = CType(IE.Document.DomDocument, HTMLDocument)
userBox = htmlDoc.all.item("user_login")
passBox = htmlDoc.all.item("user_pass")
userBox.Value = "abcdef"
|
|
|
|
|

|
For example,
int nTask = 1; \\global var
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
switch(nTask)
{
case 1:
//do something here
<- Add "System.Threading.Thread.Sleep(10000);"
nTask += 1;
break;
case 2:
//do something here
<- Add "System.Threading.Thread.Sleep(10000);"
nTask -= 1;
break;
}
}
It seems ok, but if I want to add some delay here by using "System.Threading.Thread.Sleep(10000)", the problem comes.
The whole windows will get occupied, you cannot move it and do anything on the webpages, such as click a button. I know that it is due to the current thread is holded by "System.Threading.Thread.Sleep(10000);", and the window can not response you until it is finished.
But if I cannot add delay here, where can I add the delay to make the same effect but no the problem described above?
Any help will be highly appreciated. Thanks
|
|
|
|

|
There are some websites, which need cookie to operate.
If I open several browsers in the same time, can I have a separate set of cookie to other browser?
|
|
|
|

|
I had problem with adding mshtml to project:
Error 1 The type or namespace name 'mshtml' could not be found (are you missing a using directive or an assembly reference?
I solved this by typing instead of "using mshtml;" "using MSHTML;"
maybe it will help someone
VsMax
|
|
|
|

|
Hi,
I am looking for a webclient/webbrowser component to screen scrape HTML but while scraping I want to make sure that the component reads and executes any javascript on the page. Is it possible with this component?? And also can we spoof headers for this component. Which user-agent does this component send the request from?
Thanks
|
|
|
|

|
Thanks a lot,
you're article was a great help !
I really enjoyed it.
Keep on the good work.
|
|
|
|

|
Yan can also try SWExplorerAutomation (SWEA) from Webius http://webiussoft.com[^]. SWEA automates Web Browser.The program creates an automation API for any Web application developed with HTML, DHTML or AJAX. The Web application becomes programmatically accessible from any .NET language.
SWEA API provides access to Web application controls and content. The API is generated using SWEA Visual Designer. SWEA Visual Designer helps create programmable objects from Web page content.
AlexF
|
|
|
|

|
Hi,
Does any body know how to disable this popups?
axWebBrowser.Silent =true
Does it work?
If it is work:
Where can I declare axWebBrowser.Silent property to true in the:
private void Form_Load(object sender, System.EventArgs e)
{
axWebBrowser.Silent =true
}
Or
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
axWebBrowser.Silent =true
}
Asiri
-- modified at 5:39 Friday 19th January, 2007
|
|
|
|

|
can anyone tell how to click an href link using this codehref link
sdas
|
|
|
|

|
Hi Kent,
Great Article,
It helps me lot. Thanks.
Thank you,
Asiri
-- modified at 8:44 Thursday 18th January, 2007
|
|
|
|

|
hi ther,
Thanks for your lovely blog and i wish you can help me more.
after clicking a button, i need to be able to listen to events and handle them in my application? is that possible ? if yes plesase explain how and if possible with code sample please
appreciate your help
Kind Regards
Fadil Alnassar
|
|
|
|

|
Help needed.
For example,
how to click the link?
a href="abc.asp"
|
|
|
|

|
How do I close this window and or make it not open?
|
|
|
|

|
I read what I wrote and maybe should explain the situation a bit better.
I am navigating to a web page and automatically fill in a text box with a user name and password and automate the login button as well.
This process then brings me to another page where by the URL in the browser has been dynamically created such as : www.hotmail.com/user_new.asp?forumid=26186&select=1557609&main=/csharp/mshtml_automation.asp&df=100
From within this page I can view the source code and see that there is a frame within the page I am viewing. The frame's name is "Frame1". I tried to follow your example of how to navigate to a frame but the URL that i need as the base is dynamic and I can't seem to locate it to make that frame code work.
Any ideas?
Thanks
Dave
|
|
|
|

|
Great artical!
I just have one question. If you navigate to a page that has a frame called "Frame1" on it and there are a bunch of HREF's within that Frame pointing to links that you want to navigate to, how do you iterate through the list of available links and more importantly how do you navigate to "Frame1" in the first place?
Thanks for your help
Dave
|
|
|
|
|

|
if we set a form which is a Browser.. its not working..
for eg.
browser.Form1 f = new Form1();
f.MdiParent = this;
f.show();
any thoughts ?
|
|
|
|

|
Hi,
Who i delete the bars from Control
Thanks
|
|
|
|

|
for example in this site :
http://www.google.com/advanced_search?hl=en
how i can choose an option in any of the multiline combo boxes?
like Language, File Format.....
i mean for example in Language i wanna select some language
and in file format i wanna select pdf
thx in advance....
|
|
|
|

|
Is there a way to pass credentials to the axWebBrowser to prevent the login dialog from poping up?
plclogic
|
|
|
|

|
i want drag and drop support on wbb browser control
i am draging treenode from treeview control and droping it to web browser control
which interfaces should i implement,
plz help me regarding this problem,
regards
fadi
|
|
|
|
 |