470,849 Members | 698 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Changing a form object in a page by using WebBrowser component?

Hi group,

Here's a problem I've been trying to solve for the past several weeks. I
have the standard WebBrowser object added to a form so it can access
websites, and I have it load a default page once the form is launched. I
now want to automatically fill out a specific text-field found within the
web-page that the WebBrowser object has open. Right now I am using the
following code to accomplish it:

webBrowser.Document.Forms(0)(1).Value = "Test Text"

But I am faced with a major complication when I use the above method. The
page in question is often changed and more form objects (hidden and visible)
are added, or the order of the form objects are changed. When this happens,
I have to manually go through and change the form position or the program
will error out or the text will be entered in the wrong text-field, when it
tries to add the text to the currently specified form object of (0)(1). To
make matters even worse, the page that loads will reflect what the user
selects previously, and depending on the selection the amount of form
objects on the page will change.

My question is... How can I simply search through the page and find the
NAME of the form-object I want to modify? For example, if the text-field I
want to insert the text into has a name of 'XYZ' in the HTML document, how
can I search through the page using Visual Basic and locate that element,
then once its found insert the correct text? The only element of the page
that I can seemingly do this with is the actual submit button, and I use the
code:

webBrowser.Document.All("Button").Click [ Will submit the form ]
webBrowser.Document.All("Button").Value = "Name of Button" [ Will change the
name of the button ]

When I try simular code to change the value of a text field, I get the
error: 'Object doesn't support this property or method'. So what is the
magical command to do what I am asking? I have searched MSDN and forums for
an answer, but all I can find is similar to the first line of code I
mentioned here. Is there a way to do this, it sounds like an easy task but
I can't get it to work! Thanks in advance,

Matt
Jul 17 '05 #1
1 6234
"Matt" <no**@thenewsgroups.com> wrote in message
news:qq********************@tznet.com...
Hi group,

Here's a problem I've been trying to solve for the past several weeks. I
have the standard WebBrowser object added to a form so it can access
websites, and I have it load a default page once the form is launched. I
now want to automatically fill out a specific text-field found within the
web-page that the WebBrowser object has open.


I think I found the answer! I'm now using code along the lines of:

webBrowser.Document.Forms(0).NameOfField.Value = "Whatever"

And that seems to have done the trick, so please disregard my initial
question. Unless of course you know of another alternative way that is even
better. I still haven't fully tested my solution, but I don't see why there
should be any problem.

Matt
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Wim Verhavert | last post: by
5 posts views Thread by Mike Tadd | last post: by
2 posts views Thread by jasonhartsoe | last post: by
5 posts views Thread by Kimmo Laine | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.