Buu Ngo
Buu Ngo

Reputation: 13

Submit Button that is in a Javascript using Excel VBA

I cannot seem to submit the click the submit or go button. It seems to be under a javascript which I am not sure how to enter a code to click the go button. Here is what I have:

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

Upvotes: 1

Views: 1254

Answers (2)

QHarr
QHarr

Reputation: 84475

You could also have used a css selector to target the element.

#cfmainsearchform > a

That says a tag within element with id cfmainsearchform. # is id and > within (child combinator).

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

Upvotes: 1

Tim Williams
Tim Williams

Reputation: 166895

Try this:

With IE.Document

    .getElementById("cfsearchtextboxmain").Value = _
          ThisWorkbook.Sheets("sheet1").Range("a1").Value

    .parentWindow.ExecScript "cfMainFormSubmit()"

End With

Upvotes: 1

Related Questions