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.
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)axWeb Browser1.D ocument;
mshtml.IHTMLElementCollect ion cltn = htm.getElementsByName("ema il");
but I don't know to convert the mshtml.IHTMLElementCollect ion 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#?
AxWebBrowser1.Document.All
but in C# axWebBrowser1.Document has no "All" member, ?!?!?
I have been trying somthing like this:
mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWeb
mshtml.IHTMLElementCollect
but I don't know to convert the mshtml.IHTMLElementCollect
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, ?!?!?"
ASKER
I got it to work,
htm = (mshtml.HTMLDocument)axWeb Browser1.D ocument;
mshtml.IHTMLElementCollect ion col;
col = htm.getElementsByName("ema il");
foreach (mshtml.HTMLInputElement i in col)
{
i.value = strUsername;
}
Thanks for trying to help
htm = (mshtml.HTMLDocument)axWeb
mshtml.IHTMLElementCollect
col = htm.getElementsByName("ema
foreach (mshtml.HTMLInputElement i in col)
{
i.value = strUsername;
}
Thanks for trying to help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Have a look at this sample
http://samples.gotdotnet.com/quickstart/howto/doc/WebRequests/clientPOST.aspx
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.
mblnDownloadCompleted = False
With AxWebBrowser1
.Navigate2("YourURLGoesHer
Do While Not mblnDownloadCompleted
Application.DoEvents()
Loop
.Document.All("Username").
.Document.All("Password").
.Document.Forms(0).Submit(
mblnDownloadCompleted = False
Do While Not mblnDownloadCompleted
Application.DoEvents()
Loop
btnGo.Enabled = True
End With