?
Solved

Using axWebBrowser to input text to a web textbox

Posted on 2004-11-06
8
Medium Priority
?
396 Views
Last Modified: 2012-08-13

   I am working in visual studio .net, I have created a window app and added an axWebBrowser with the standard navigation buttons, this works fine. I would like to be able to load a page with multiple textboxs and buttons then programmaticlly input text to a specific textbox and then fire a specific button. Say for example to automatically login to a web site.

Can I do this with axWebrowser or an mshtml.HTMLDocument ?

I have played with mshtml.HTMLDocument a little and am able to grab the text of the page but I can't figure out how to get access to textboxes or buttons.

Please give an example of how this can be done.
0
Comment
Question by:Pursuer
  • 4
  • 3
8 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12513307
I use the axWebBrowser like this:

        mblnDownloadCompleted = False
        With AxWebBrowser1
            .Navigate2("YourURLGoesHere")
            Do While Not mblnDownloadCompleted
                Application.DoEvents()
            Loop
            .Document.All("Username").Value = "YourUID"  'You may have to change UseName for your field name
            .Document.All("Password").Value = "YourPassword" 'You may have to change Password for your field name
            .Document.Forms(0).Submit()

            mblnDownloadCompleted = False
            Do While Not mblnDownloadCompleted
                Application.DoEvents()
            Loop
            btnGo.Enabled = True
        End With
0
 

Author Comment

by:Pursuer
ID: 12513500
Is that VB? I am working in C#, I have seen similar VB examples

AxWebBrowser1.Document.All("Username").Value = "YourUID"

but in C# axWebBrowser1.Document has no "All" member, ?!?!?


I have been trying somthing like this:

mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWebBrowser1.Document;
mshtml.IHTMLElementCollection cltn = htm.getElementsByName("email");

but I don't know to convert the mshtml.IHTMLElementCollection to a mshtml.HTMLInputElement
so I can access its value. Im not even sure if this is the right approach. Can you give me an example in C#?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12513521
why don't you use the axWebBrowser ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12513523
I just saw "but in C# axWebBrowser1.Document has no "All" member, ?!?!?"
0
 

Author Comment

by:Pursuer
ID: 12513718
I got it to work,

htm = (mshtml.HTMLDocument)axWebBrowser1.Document;
mshtml.IHTMLElementCollection col;
col = htm.getElementsByName("email");

foreach (mshtml.HTMLInputElement i in col)
{
     i.value = strUsername;
}

Thanks for trying to help
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 1500 total points
ID: 12513846
I was having that:

                  mshtml.IHTMLDocument2 doc;

                  doc = (mshtml.IHTMLDocument2) this.axWebBrowser1.Document;
                  mshtml.HTMLInputElement x = (mshtml.HTMLInputElement)doc.all.item("UserName",null);
                  x.value="YourUID";

I was looking for the submit button
0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12522065
why are you not simply posting to the second page instead of loading the first, filling it out, hunt for the submit button and fake a click?

Have a look at this sample
http://samples.gotdotnet.com/quickstart/howto/doc/WebRequests/clientPOST.aspx
0
 

Author Comment

by:Pursuer
ID: 12524569
logging on to a web site was just an example, in some cases where I want to use this there is no second page.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question