Using axWebBrowser to input text to a web textbox

   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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
I use the axWebBrowser like this:

        mblnDownloadCompleted = False
        With AxWebBrowser1
            Do While Not mblnDownloadCompleted
            .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

            mblnDownloadCompleted = False
            Do While Not mblnDownloadCompleted
            btnGo.Enabled = True
        End With
PursuerAuthor Commented:
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#?
Éric MoreauSenior .Net ConsultantCommented:
why don't you use the axWebBrowser ?
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Éric MoreauSenior .Net ConsultantCommented:
I just saw "but in C# axWebBrowser1.Document has no "All" member, ?!?!?"
PursuerAuthor Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
I was having that:

                  mshtml.IHTMLDocument2 doc;

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

I was looking for the submit button

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
PursuerAuthor Commented:
logging on to a web site was just an example, in some cases where I want to use this there is no second page.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.