提交按钮,该按钮位于使用 Excel VBA 的 Javascript 中

Submit Button that is in a Javascript using Excel VBA

本文关键字:按钮 VBA Excel Javascript 于使用 提交      更新时间:2023-09-26

我似乎无法提交单击提交或转到按钮。 它似乎在一个javascript下,我不确定如何输入代码来单击go按钮。 这是我所拥有的:

Sub FactFinderForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
'create new instance of IE. use reference to return current open IE if
'you want to use open IE window. Easiest way I know of is via title bar.
IE.Navigate "http://factfinder.census.gov/faces/nav/jsf/pages/index.xhtml###"
'go to web page listed inside quotes
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
IE.Document.getElementsByname("cfsearchtextboxmain").Item.innertext = _
              ThisWorkbook.Sheets("sheet1").Range("a1")
While IE.readyState <> 4
DoEvents
Wend
SendKeys "{enter}"
End Sub

试试这个:

With IE.Document
    .getElementById("cfsearchtextboxmain").Value = _
          ThisWorkbook.Sheets("sheet1").Range("a1").Value
    .parentWindow.ExecScript "cfMainFormSubmit()"
End With

您也可以使用 css 选择器来定位元素。

#cfmainsearchform > a

也就是说a id为cfmainsearchform的元素中的标签。 #是 id 和 > 在(子组合器(。

ie.document.querySelector("#cfmainsearchform > a").Click