【问题标题】:Entering text into webpage searchbox在网页搜索框中输入文本
【发布时间】:2020-12-24 15:50:52
【问题描述】:

我正在尝试在搜索框中输入文本并遇到不同的错误。下面是我的代码,谁能指出我哪里出错了?

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"

结束子

【问题讨论】:

  • 我在下面分享的 VBA 示例是否帮助您解决了这个问题?如果是,您可以尝试接受答案。它可以在未来帮助其他社区成员解决类似的问题。感谢你的理解。 See here

标签: html internet-explorer getelementsbyclassname search-box ihtmldocument


【解决方案1】:

我建议尝试使用下面的代码示例进行测试可能有助于解决问题。

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

输出:

此外,您可以根据需要修改代码示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    相关资源
    最近更新 更多