I am attempting to use a search box on a website to find a client. I can input information to Internet Explorer with the code under my "Log on to website" portion, but when I attempt to search for the client, the objects I try always are null.
VBA Code
Sub main()
' IE object to pass to all functions
Dim IE As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' URL for website login
Dim URL As String
URL = "https://www.website.com"
' Search bar object (for homepage)
Dim searchBar As Object
IE.Visible = True
IE.navigate URL
' Load webpage completely
Do Until Not IE.busy And IE.readystate = 4
DoEvents
Loop
' Log on to website
IE.document.getElementByID("UserName").Value = "myUsername"
IE.document.getElementByID("Password").Value = "myPassword"
' Time delay ensures entry of username and password
Application.Wait (Now + TimeValue("00:00:02"))
IE.document.getElementByID("btnLogin").Click
' Load webpage completely
Application.Wait (Now + TimeValue("00:00:02"))
Do Until Not IE.busy And IE.readystate = 4
DoEvents
Loop
' Search for client by ID on "Home" tab
' This doesn't work
IE.document.all("form1").Name("Searchfor").Value = "clientID"
IE.document.all("form1").Name("search").Click
' This doesn't work
IE.document.getElementsByName("Searchfor")(0).Value = "clientID"
IE.document.getElementsByName("search")(0).Click
End Sub
HTML Code (I tried to put spaces here to make it more readable, but I don't know HTML so it may be split up incorrectly)
<form name="form1" id="form1" action="/common/my_cw.asp" method="post">
<table width="255" border="0" cellspacing="0" cellpadding="2"><tbody>
<tr><td nowrap="">
<input name="Searchfor" onclick="if (this.value == 'NAME / ID') this.value=''"
onblur="if (this.value == '')
this.value='NAME / ID'" type="text" size="20" value="NAME / ID">
<input name="search" type="submit" value="Search"></td></tr>
<tr><td>
<input name="searchtype" type="radio" checked="" value="C">Client
<input name="searchtype" type="radio" value="E">Employee</td></tr>
</tbody>
</table>
</form>
I have also tried getElementsByTag("input") and using a for each loop with no success.
Please let me know if additional HTML code is needed.