Link to home
Start Free TrialLog in
Avatar of Pursuer
Pursuer

asked on

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.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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
Avatar of Pursuer
Pursuer

ASKER

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#?
why don't you use the axWebBrowser ?
I just saw "but in C# axWebBrowser1.Document has no "All" member, ?!?!?"
Avatar of Pursuer

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start 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
http://samples.gotdotnet.com/quickstart/howto/doc/WebRequests/clientPOST.aspx
Avatar of Pursuer

ASKER

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