0

我在网页中有以下代码。

<form class="search" target="_blank" method="get" action="Search.mvc/advanced">
    <input aria-haspopup="true" aria-autocomplete="list" role="textbox" autocomplete="off" class="quick ui-autocomplete-input" name="q" id="search-box" placeholder="Search" type="search">
    <button type="button" class="advanced" title="Advanced Search"><span class="icon"></span></button>
</form>

我想单击为搜索框提供的按钮。网页代码没有标签名称或 ID。

我正在使用 IE 8 浏览器。

4

2 回答 2

1

尝试使用 CSS 选择器,例如:

ie.Document.querySelector("button.advanced").Click
于 2018-05-05T12:52:59.777 回答
0

试试这个代码...

(手写输入未经测试的代码,所以可能有错别字。如果它不起作用,请报告)

Sub ClickIEButton()
    Dim ie As Object
    Dim form As Variant, button As Variant

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Naviagate ("http://whateverwebsite.com")
    While ie.ReadyState <> 4
        DoEvents
    Wend

    Set form = ie.Document.Body.GetElementsByTagName("form")(0) '<-- You may need to change this 0 to 1 or 2 or 3 etc....
    Set button = form.GetElementsByTagName("button")(0)  '<-- You may need to change this 0 to 1 or 2 or 3 etc....
    button.Click
End Sub
于 2012-10-01T09:11:39.000 回答