【问题标题】:Submit Button that is in a Javascript using Excel VBA使用 Excel VBA 提交 Javascript 中的按钮
【发布时间】:2015-04-08 21:05:11
【问题描述】:

我似乎无法提交单击提交或执行按钮。它似乎在一个 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

【问题讨论】:

    标签: javascript excel vba internet-explorer web-scraping


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

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

      #cfmainsearchform > a
      

      这表示 a 标记在 ID 为 cfmainsearchform 的元素中。 # 是 id,&gt; 在 (child combinator) 内。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-27
        • 1970-01-01
        • 2016-08-23
        • 2013-04-09
        • 2020-08-15
        • 2011-11-25
        • 1970-01-01
        相关资源
        最近更新 更多