Programmatically Fire jQuery AutoComplete on Webpage with Excel VBA
I'm trying to invoke a search on a website to navigate to a specific page using VBA in Excel. The search is being completed using jQuery auto-complete which submits a form that navigates to a page after an item from the auto-complete box has been selected. I'm able to populate the input box connected to the auto-complete box with the text I want it to find, but the webpage lacks a submit button to submit the results to a form. Instead, it requires you to select an item in the auto-complete box which then automatically fires the submit form event.
I need help figuring out how to pass the search string to the related auto-complete box and then fire it's associated function to submit the form. I'm trying this in VBA in Excel, but suggestions in javascript, jQuery, etc... may help point me in the right direction, so any feedback is appreciated.
Any thoughts?
I tried using SendKeys, but can't get it to work (plus it's not preferred method).
Basic Html (tried to give strip down version. forgive me if I missed anything, but this should give you the jist):
- <html>
- <head>
- function noenter() {
- return !(window.event && window.event.keyCode == 13);
- }
- $(document).ready(function() {
- autoComp = $('#search).autocomplete({
- serviceUrl:'search.aspx',
- params: {param1:'abc', param2:'xyz'},
- onSelect: function(value, data){
- document.formSearch.pageID.value = data;
- document.formSearch.submit();
- }
- }
- });
- </head>
- <body>
-
- <form method="get" name="formSearch" action="page2.aspx">
- <input id="pageID" type="hidden" value="">
- </form>
-
- <input type="text" id="search" name="search" onKeyPress="return noenter();" >
-
- </body>
- </html>
Code in Excel:
- Sub SearchThenGoToPage()
- myURL = "http://www.mywebiste.com/page1.aspx"
-
- Set myIE = New InternetExplorer
- myIE.Visible = True
- myIE.navigate myURL
-
- Do While myIE.Busy Or myIE.readyState <> 4
- DoEvents
- Loop
-
- myDocument.getElementsByName("search").Item(0).Value = "Item 1"
-
- 'SendKeys method. Which I don't like and doesn't work anyway.
- AppActivate "Internet Explorer"
- myDocument.getElementsByName("search").Item(0).Focus
- SendKeys "{DOWN}"
- SendKeys "{ENTER}"
-
- 'Assuming text 'Item 1' is perfect and found by jQuery auto-complete,
- 'this should select the first item in the auto-complete list and then
- '{enter} is passed which should invoke the submit form event.
-
- 'Then when I get to my new page, I parse the html and dsiplay it in Excel.
- 'All done.
-
- myIE.Quit
- Set myIE = Nothing
- End Sub