Form.Submit fails when using VBA

I have a webpage from which I am retrieving data. I can do everything perfectly with VBA, except by clicking on the image element, which then submits the form, and a data popup is created.

One of the attributes in the image element is called "productguid" and has string value =

"a12-545".

The HTML code for the form looks like this before I click on the image element with the mouse.

<form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post"> <input type="hidden" name="ProductGuid" value=""> </form> 

This is the HTML code AFTER I manually click on it with the mouse:

 <form id="GetProductQuantitiesForAccessibleBranches" action="GetProductQuantitiesForAccessibleBranches" method="post"> <input type="hidden" name="ProductGuid" value="a12-545"> </form> 

Based on this, I assumed that the productguid value from the image element is passed to the form before it is submitted. Here is what my VBA code looks like:

 'Change the input element value ie.Document.getElementById("GetProductQuantitiesForAccessibleBranches").all.item(0).value = "a12-545" 'Submit the form ie.Document.getElementyId("GetProductQuantitiesForAccessibleBranches").Submit 

According to the Locals window, all Javascript Null events. Both lines of code run without errors, but the web page does not refresh. Did I miss something?

I also tried just clicking on an image element using the .Click method, but that does nothing either.

The webpage is password protected, so I cannot publish this URL publicly.

UPDATE:

Here is the HTML in the tag, which is usually clicked manually, which then submits the form. Maybe there is something here that I can use?

 <img alt="View Quantities At Other Locations" src="/WebOrder/Images/CheckQtys.gif" title="View Quantities At Other Locations" class="popup" popupdirection="upperleft" popupwidth="380" popupcontent="#ProductQuantitiesForAccessibleBranches" onbeforepopupcreate="onBeforePopupCreate_GetProductQuantitiesForAccessibleBranches(this)" popupajaxformid="GetProductQuantitiesForAccessibleBranches" onbeforepopupajaxpost="onBeforePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" oncompletepopupajaxpost="onCompletePopupAjaxPost_GetProductQuantitiesForAccessibleBranches(this)" productguid="a12-545" displayitem="33902" brandguid="00000000-0000-0000-0000-000000000000" brandname="" brandsku=""> 
+5
source share
1 answer

Give this snapshot, I doubt it would be the β€œperfect” answer without actually viewing the site. However, this should find the correct image tag if you do not have frames / frames (please check if there are any) and click on it.

 Public Sub Click_IMG_Tag() Dim Elements As Object Dim Element As Object 'Get a pointer to IE etc first, I'm assuming this is already done Set Elements = IE.Document.getElementsByTagName("img") For Each Element In Elements On Error Resume Next ' used to bypass elements that don't have .Title property ' later, you should error handle this exception If Element.Title = "View Quantities At Other Locations" Then Element.Focus Element.Click Element.FireEvent ("OnClick") IELoad IE Exit For End If Next End Sub Public Sub IELoad(Browser As Object) While Browser.busy Or Browser.Readystate <> 4 Application.Wait (Now() + TimeValue("00:00:01")) DoEvents Wend End Sub 
+3
source

All Articles