Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在网页搜索框中输入文本_Html_Internet Explorer_Getelementsbyclassname_Search Box_Ihtmldocument - Fatal编程技术网

Html 在网页搜索框中输入文本

Html 在网页搜索框中输入文本,html,internet-explorer,getelementsbyclassname,search-box,ihtmldocument,Html,Internet Explorer,Getelementsbyclassname,Search Box,Ihtmldocument,我试图在搜索框中输入文本,但遇到了不同的错误。下面是我的代码,谁能告诉我哪里出了问题 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

我试图在搜索框中输入文本,但遇到了不同的错误。下面是我的代码,谁能告诉我哪里出了问题

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"
子GetHTMLDocument()
Dim IE作为新的SHDocVw.InternetExplorer
将HTMLDoc设置为MSHTML.HTMLDocument
将HTMLInput设置为MSHTML.IHTMLElement
可见=真实
即“导航”http://shopee.sg"
在IE.readyState readyState\u完成时执行此操作
环
设置HTMLDoc=IE.document
设置HTMLInput=HTMLDoc.getElementsByClassName(“shopee-searchbar-input\uuuu输入”)
HTMLInput.Value=“Excel VBA”
端接头


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

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
输出:


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

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