在加载的网页上打锚定标记button,并用vba打okbutton

我有下面的代码加载网页。 我想点击加载的网页上的“高级search”锚点标记,然后点击确定button。

Option Explicit Sub SaveHTml() Dim str1, str2, str3, str4, str5, str6, str7, URL As String Dim ie, frm As Object Dim i As Long Dim filename As String Dim FF As Integer 'Dim elems As IHTMLInputTextElement Dim wb As WebBrowser Dim objElement As Object Dim objCollection As Object Dim Button As Object 'On Error Resume Next Application.ScreenUpdating = False str1 = Sheets("PR_data_with_search").Range("F10").Value str2 = Sheets("PR_data_with_search").Range("I10").Value URL = "https://webtac.industrysoftware.automation.com/webpr/webpr.php?objtype=frames" 'for TEST filename = "C:\Users\" & Environ("UserName") & "\Desktop\Test.htm" Set ie = CreateObject("Internetexplorer.Application") ie.Visible = True ie.Navigate URL Do Until ie.ReadyState = 4 DoEvents Loop Set ie = Nothing ' load next web page Dim i1 As Integer Dim txt, p As String, link As String txt = "Advanced Search" Do Until link = txt i1 = i1 + 1 p = ie.Document.Links(i1).tostring link = Right(p, 6) Loop ie.Document.Links(i).Click ie.Document.getelementsbyname("openedFrom_dateText")(0).Value = str1 ie.Document.getelementsbyname("openedTo_dateText")(0).Value = str2 'Call ie.Document.getElementsByTagName("ok").Item(1).Click Set Button = ie.Document.getElementById("ok") Button.Click Do Loop While ie.Busy CreateObject("Scripting.FileSystemObject").CreateTextFile filename Do Until ie.ReadyState = 4 DoEvents Loop FF = FreeFile Open filename For Output As #FF With ie.Document.body Print #FF, .outerHTML & .innerHTML End With Close #FF ie.Quit Set ie = Nothing Application.ScreenUpdating = True End Sub 

高级search定位标记的html代码是:

 <li><a href="javascript:parent.gotoSearch('advanced')">Advanced Search</a></li> 

对于网页上的确定button是:

 <input type=button name="ok" id="ok" value=" OK " onClick="onSubmitFunction()">