 |
|
 |
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!
|
|
|
|
 |
|
 |
var button = (HtmlButtonElement)
(from IHTMLElement i in myDoc.all
where i is HTMLButtonElement
&& i.outerHTML.indexOf("önclick=\"sendData(322, 1);\"" != -1
select i).FirstOrDefault();
button.click();
modified on Sunday, May 9, 2010 9:02 PM
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
You can use this logic to detect load page complete
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (_browser.ReadyState != WebBrowserReadyState.Complete)
{
return;
}
if ((e.Url.AbsolutePath == "blank" || e.Url.AbsolutePath == "about:blank") || (e.Url != _browser.Url))
{
return;
}
_loadcomplete = true;
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
It's very simple.
First, I got a collection of textarea elements
IHTMLElementCollection TextAreaElemets = objDoc.getElementsByTagName("textarea");
After is the most important part, that I covert IHTMLElement to IHTMLTextAreaElement
I use foreach to go throw the collection.
After use TextAreaElement is not hard.
Of course, yo must control your wanted textarea by name tag
foreach (IHTMLElement Element in TextAreaElemets)
{
IHTMLTextAreaElement TextAreaElement = Element as IHTMLTextAreaElement;
TextAreaElement.value = "My value";
}
|
|
|
|
 |
|
 |
How do i click a dynamic javascript button or object like adsense in a web page?
|
|
|
|
 |
|
 |
hi Lalspo,
Not sure whether this is the solution that you want. I just found a solution for pressing "Enter" Key. use SendKeys.Send("\r"); to query "enter". I m also still finding the solution on how to click the button on the website.
Regards,
YB
|
|
|
|
 |
|
 |
I have Problem.
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!
|
|
|
|
 |
|
 |
I mean to accept or cancel download automatically!
thanks
|
|
|
|
 |