The following code works well to click a search button, so long as the element has an assigned tag name. Unfortunately I am not able to locate a name element for the Search button on the Yahoo home page. Can someone PLEASE advise on how to successfully re-write the code shown below to click the Yahoo home page Search button. Thank You.
Yahoo Search Button
Code:
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Set objIE = New SHDocVw.InternetExplorer
With objIE
.navigate "https://Yahoo.com" ' Main page
.Visible = 1
Do While .Busy: DoEvents: Loop
Do While .readyState <> 4: DoEvents: Loop
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("INPUT")
For Each htmlInput In htmlColl
If htmlInput.Name = "search" Then
htmlInput.Value = Replace(Userform.Textbox.Value, " ", "+")
End If
Next htmlInput
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("input")
Do While htmlDoc.readyState <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If htmlInput.Name = "go" Then
htmlInput.Click
End If
Next htmlInput
End With
Yahoo Search Button
HTML:
<button tabindex="3" title="Search Web" class="rapid-noclick-resp C(#fff) Fz(16px) Px(26px) Py(0) Whs(nw) Bdw(0) Lh(1) enableHover_Bgc($searchBtnHov):h W(80px) Bdrststart(0) Bdrsbstart(0) Bxsh(n) H(46px) Miw(90px) Bgc(#0f69ff) Bgc(#145aff):h Bgc(#145aff):f glow_Bgc($searchBtnGlow) Bdrs(2px) Bxsh(n)! ua-ie7_H(42px) ua-ie7_Lh(42px) ua-ie8_Lh(42px) ua-ie8_Miw(a)" id="uh-search-button" aria-label="Search Web" type="submit" data-ylk="rspns:nav;t1:a1;t2:srch;sec:srch;slk:srchweb;elm:btn;elmt:srch;tar:search.yahoo.com;tar_uri:/search;itc:0;" data-rapid_p="33"><i class="Fz(26px) Mstart(2px) Icon-Fp2 IconNavSearch Icon-Fp2"></i>
</button>
Last edited: