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