I am new to web scraping and VBA but am eager to learn further. I have a small project in mind and am taking it slowly one step at a time. I have a small piece of code in an Excel module which is almost working. I just cannot get it to submit my search box text. I basically have the example horse name in Cell A2 in my Excel worksheet. The code opens the website and also enters the text into the search box. I just can't get it to click the Go button. I'd appreciate any help and an explanation of what I'm doing wrong so I can avoid it again!
When inspecting the Go button on the site, the HTML is thus:
My code:
Sub HorseSearch()
'define objIE
Dim objIE As InternetExplorer
'create an instance objIE
Set objIE = New InternetExplorer
'make web page visible
objIE.Visible = True
'navigate objIE to this web page
objIE.navigate "https://www.britishhorseracing.com/racing/horses/racehorse-search-results/"
'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
'in the search box put cell "A2" value which holds a horse name Tiger Roll
objIE.document.getElementById("text-search").Value = Sheets("Sheet1").Range("A2").Value
'place focus on the Go button
objIE.document.getElementById("Submit").Focus
'click the 'go' button
objIE.document.getElementById("Submit").Click
End Sub