• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Web Automation - Submit / Click wont POST chosen IMAGE type values

I have managed to automate a login to an external trading web site using the InternetExplorer.Application object model via Excel VBA, supplying user name, password and submitting the page.  That works.  I then select a desired company to trade via a calculated URL (now I'm in) and am presented with a few input boxes, radio buttons and two image buttons at the bottom of the page, [Buy] or [Sell].  
When I use a click or submit method on the "Sell" document object, it always starts the "Buy" page (presumabaly the default).  Have manually set focus on the web page to [Sell] using tab key and pressed [Enter], but it also reverts to "Buy" page.  However a manual left mouse click on [Sell] button works as expected.  The form action launches an ActiveServerPage, so the destination URL e.g. http://www.asite.com/next_process.asp. does'nt really help me.

Most question/answers I have looked at seem to refer to non "Image" input type objects or possibly where only one submit option is available.  A few found in other groups imply image buttons maybe posting mouse cordinates and other variables.

So I guess my question/s is does anybody know how I can programatically launch the "Sell" button correctly.  I'm still a newbie with regard to the internet object model, so be gentle with me.

HTML Source Extract:
<form action="next_process.asp" name="atrade" ID="atrade" method="post" onsubmit="return ChkFrm(this)">
<td colspan="2">
   <input TYPE="hidden" value="123456" name="PortfolioID">
   <input TYPE="hidden" value="654321" name="CompanyID">
   <input type="image" src="http://asite.com/butt_buy.gif" value="Buy" name="buy"> <!---onClick="submit()"--->
   <input type="image" src="http://asite.com/butt_sell.gif" value="Sell" name="sell"><!---onClick="submit()"--->

My VBA Code Extract:

Dim inp As Object
Set IE = CreateObject("InternetExplorer.Application")
Set inp = IE.Document.All.Item("sell")

1 Solution
Post the code for ChkFrm function (inside the html document), that may help.
Once the page is loaded, you can search for the "Sell" button like this:

Dim inputCollection As Object
Dim inp As Object

'get all the input elements
Set inputCollection = IE.Document.getElementsByTagName("input")

'search for the sell button
For Each inp In inputCollection
    If inp.Name = "sell" Then
        Exit For
    End If
skg83239Author Commented:
Thanks for the replies so far.  With regard to first, the

function CheckForm(trade)
if (trade.number.value == '')
                        alert('Enter the number');
                        return false;
                  return true;
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

skg83239Author Commented:
Sorry, submitted previous reply comment too early.  I'll have to watch the tab key!
The function was one of my thoughts initially, but ChkFrm(this) is as above CheckForm function.  It appears to simply check the quantity of shares being sold/bought ("number") on the web page/form ("trade").  It prompts the user to enter a value if the "number" input box is empty, then aborts the submit process (with return value of FALSE).  However I do not alter the default value presented (which is the total number shares owned for that company), so is not part of the problem.  

Second reply, thanks also. Unfortunately it ultimately replicates the lines below, which directly assign the object variable "inp" to the "sell" object on the web page.

    Set inp = IE.Document.All.Item("sell")

I did try it all the same, and compared attributes to ensure it was the same object, but got the same result when click method executed; goes to "buy" page instead.

I'm pretty sure that the Click method is simply not enough information for the posted asp.  The INPUT type=image, appear to work differently from other button/submit input types.  

I found one site http://www.chami.com/tips/internet/042399I.html
which shows an example of multiple image type buttons, from a HTML stance.  The ASP part appears to check for the relative offset x and y coordinates of the submitted/clicked image button.

Not sure how this can be applied in a VB code sense.  Perhaps I do not need to submit/click to proceed to the sell page, but can supply generate a URL address instead, e.g.,


I'll let you know how I get on, but all suggestions etc. to date and following are appreciated.
skg83239Author Commented:

Passing the POST data via the URL worked partially.  The Sell screen was delivered, but not all the variables were transferred across.  Tried different orders and ensured case and spelling were correct.  For some reason both inputs/variables were the only ones to have a text value.  

Most URL examples I've seen do not use any specific text identifies such as quotes (e.g. tried  ...next_process.asp?Number1234&atext1=a OR ...&Number1234&atext1='a' OR ...&Number1234&atext1="a" ).  Checking the source of the following page confirmed they did not get across.  This is another question and redundant, if I can simulate the user click on the form "Sell" image button.  

The direct URL approach did confirm to me that the coordinates were an important characteristic of the image input type, as putting xy values exclusively against either the buy or sell had the desired result.

Either the values can be POSTed differently to the following form ASP via e.g. Navigate method, or some kind of mouse move to position of the button is required.  The later obviously may need a lot more validation such as desktop resolution and ensuring the browser window is maximised.  Not sure if this can be done via VBA?

If possible I would like to keep the solution in VB/VBA rather than having to use a third party package.
Any more thoughts?
skg83239Author Commented:
Thanks Dan,
In the absence of any suggestions I have used VBA to control the mouse.

PAQed with points refunded (500)

Community Support Moderator

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now