Fill and submit the input box on IE with VB
Assume that the HTML code of the logon page is as follows:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> testpage </title>
</Head>
<Body>
<Form name = chh method = "Post" Action = "login. asp">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "2">
<Tr>
<TD width = "31%" align = "center"> User: </TD>
& Lt; TD width = "69%" align = "Left" & gt;
<Input name = "loginname" type = "text" id = "loginname" size = "12">
</TD>
</Tr>
<Tr>
<TD width = "31%" align = "center"> password: </TD>
& Lt; TD width = "69%" align = "Left" & gt;
<Input name = "loginpassword" type = "password" id = "loginpassword" size = "12">
</TD>
</Tr>
</Table>
<Input type = "Submit" id = "clickme" value = "Submit">
</Form>
</Body>
</Html>
On the simple page, there is a login form, a username input box loginname, a password input box loginpassword, and a submit button clickme.
Then open the page with IE. Note that the title of the page is set to testpage.
Open VB and reference Microsoft Internet controls in the project:
Private sub commandementclick ()
Dim ielist as new shellwindows
Dim Browser
Dim Doc
On Error resume next
'Traverse the current local browser window
For each browser in ielist
'Locate the required ie window
If browser. Document. Title = "testpage" then
'Get the file objects in the browser.
Set Doc = browser. Document
'Fill In the username field
Doc. Body. All ("loginname"). value = "Eddie"
'Fill in the password field
Doc. Body. All ("loginpassword"). value = "123456"
'Submit
Doc. Body. All ("clickme"). Click
End if
Next
End sub