I'm having trouble when trying to click a search button on a webpage via Excel VBA. Actually, my real issue has to deal with the particular webpage not seeing that I entered something in the search box. After I click the search button on the webpage I get the message saying "Provide a number or company name to search" when there's already something in the search box.
Before the Text is entered into the Search Box:
After the Text is entered into the Search Box & the Search button is clicked:
Here's the portion of the HTML source where the button (and onclick
event) is present. The specific line for the button is
<a href="#" class="add-on" data-bind="click: performSupplierSearch"><i class="icon-search">
<div class="row-fluid">
<div class="span6">
<h4>Search for the supplier you wish to Log in as:</h4>
<span class="helpText-SearchSupplier">Search by name or number</span>
</div>
</div>
<div class="row-fluid block">
<div class="span4 input-append pull-left">
<input id="supplierSearchTextBox" data-bind="value: searchQuery, valueUpdate: 'afterkeydown', onEnter: performSupplierSearch" type="text" class="input-xlarge" autocomplete="off" placeholder="Search Suppliers" />
<a href="#" class="add-on" data-bind="click: performSupplierSearch"><i class="icon-search"></i></a>
</div>
</div>
<div class="row-fluid" data-bind="visible: searched() && supplierSearchResults().length == 0">
<div class="span12">
<div class="alert ">
<strong><i class="icon-warning-sign"></i> 0 results returned </strong>
</div>
</div>
</div>
<div class="row-fluid" data-bind="visible: (searchMessage().length > 0)">
<div class="span12">
<div class="alert ">
<strong><i class="icon-warning-sign"></i><span data-bind="text: searchMessage"></span></strong>
</div>
</div>
</div>
When I inspect the elements of the HTML and click on the Search button it invokes y.handle
, which I followed to a jquery file and found these two code snippets that mention said y
(p=y.events)||(p=y.events={})
amidst this function in the jquery file
add:function(n,r,u,f,e){var b,p,k,w,c,l,a,v,h,d,g,y=i._data(n);if(y){for(u.handler&&(w=u,u=w.handler,e=w.selector),u.guid||(u.guid=i.guid++),(p=y.events)||(p=y.events={}),(l=y.handle)||(l=y.handle=function(n){return typeof i===o||n&&i.event.triggered===n.type?t:i.event.dispatch.apply(l.elem,arguments)},l.elem=n),r=(r||"").match(s)||[""],k=r.length;k--;)b=sr.exec(r[k])||[],h=g=b[1],d=(b[2]||"").split(".").sort(),c=i.event.special[h]||{},h=(e?c.delegateType:c.bindType)||h,c=i.event.special[h]||{},a=i.extend({type:h,origType:g,data:f,handler:u,guid:u.guid,selector:e,needsContext:e&&i.expr.match.needsContext.test(e),namespace:d.join(".")},w),(v=p[h])||(v=p[h]=[],v.delegateCount=0,c.setup&&c.setup.call(n,f,d,l)!==!1||(n.addEventListener?n.addEventListener(h,l,!1):n.attachEvent&&n.attachEvent("on"+h,l))),c.add&&(c.add.call(n,a),a.handler.guid||(a.handler.guid=u.guid)),e?v.splice(v.delegateCount++,0,a):v.push(a),i.event.global[h]=!0;n=null}},remove:function(n,t,r,u,f)
I don't know if the jquery code will help at all, but I figure it couldn't hurt to give as much information as I could to increase the odds of at least one person being able to help me resolve this.
Here is the portion of my code where I'm attempting to enter the text and click the button
'Select Search Box
IE.document.GetElementByID("supplierSearchTextBox").Focus
'Fill in Search Box
IE.document.GetElementByID("supplierSearchTextBox").Value = "Test"
delay 3
'Click Search button
Dim searchButton As Object
'6th a tag so index 5
Set searchButton = IE.document.GetElementsByTagName("a")(5)
searchButton.Click
Am I entering the Value in the wrong way/with the wrong method or does it have something to do with the onclick event that's attached to the search button that is the problem? How can I get the code to work correctly?