0

I am trying to enter text into a searchbox and am running into different errors. Below is my code, can anyone point out to me where i have gone wrong?

Sub GetHTMLDocument()

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement


IE.Visible = True
IE.navigate "http://shopee.sg"

Do While IE.readyState <> READYSTATE_COMPLETE
Loop


Set HTMLDoc = IE.document
Set HTMLInput = HTMLDoc.getElementsByClassName("shopee-searchbar-input__input")
HTMLInput.Value = "Excel VBA"

End Sub

enter image description here

  • Does the VBA example I shared below helped you to solve the issue? If yes, you can try to accept the answer. It can help other community members in the future in similar kinds of issues. Thanks for your understanding. [See here](https://stackoverflow.com/help/someone-answers) – Deepak-MSFT Sep 11 '20 at 09:05

1 Answers1

0

I suggest try to make a test with the code sample below may help to solve the issue.

Sub demo()

    Dim URL As String
    Dim IE As Object
    Dim element As HTMLInputElement
    Set IE = CreateObject("InternetExplorer.Application")
   
    IE.Visible = True
    
    URL = "YOUR WEB PAGE ADDRESS HERE" 'Add your site address here....
 
    IE.navigate URL

    Do While IE.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
    Application.Wait DateAdd("s", 2, Now)
    Set element = IE.document.querySelector("[class='shopee-searchbar-input__input']")
    element.removeAttribute ("aria-label")
    element.removeAttribute ("placeholder")
    element.Value = "abc"
    element.FireEvent ("OnChange")
    Set IE = Nothing
   
End Sub

Output:

enter image description here

Further, you can modify the code example as your requirements.

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19