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

Posted on 2005-02-24
Medium Priority
Last Modified: 2010-05-02
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")

Question by:skg83239
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Expert Comment

ID: 13395937
Post the code for ChkFrm function (inside the html document), that may help.
LVL 32

Expert Comment

ID: 13396043
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

Author Comment

ID: 13403846
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;
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 13404844
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.

Author Comment

ID: 13440448

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?

Author Comment

ID: 13749193
Thanks Dan,
In the absence of any suggestions I have used VBA to control the mouse.


Accepted Solution

modulo earned 0 total points
ID: 13792799
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question