Solved

html submit automatically.

Posted on 2006-11-28
15
583 Views
Last Modified: 2013-11-13
Hello Experts!

I have asked this before but did not get any good answer that would help me.

I would like to write a piece of code where I use the vb ie explorer control to navigate to page and on timer do different things, like submit operations. I will simply add "tasks" to a list and from that on every x seconds/minutes, different pages will be navigated to, values (dropdown boxes) will be chosen and then submited automatically.

is it possible?

I have done it with imputting login/pass and then submitting but never with drop down boxes, can it be done?

/BK
0
Comment
Question by:Berhan Karagoez
  • 9
  • 5
15 Comments
 
LVL 11

Expert Comment

by:SweatCoder
Comment Utility
Probably can be done, but it's difficult. There are commercial apps that do this kind of thing. Search on google for "web application test automation". If you really want to roll your own, you might try .NET 2.0 browser apis, or windows script host (vbs).
0
 

Author Comment

by:Berhan Karagoez
Comment Utility
I already know it' probably can be done and it's difficult. :)

I was hoping someone could tell me how?!

/BK
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
you cannot automate the actions you described with IE control.

I have only done this before in Delphi as it has the Indy HTTP control that handles POST and GET automatically without you coding it.

But, you can code it yourself with the VB Winsock control.

submitting a form is essentialy the same as using the POST or GET request to the distination URL.

eg:
<form method=POST action='http://www.test.com/login.php>
<input name=username>
</form>

to automatically submit this form, you will simply use the winsock control to connect to port 80 or the IP address(you need to do a look up on the domain name), then do a HTTP POST request:


POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded

name=blah


(read here:)
http://developers.sun.com/techtopics/mobility/midp/ttips/HTTPPost/ (details)


as you may notice this is a rather complex coding process, because you also need to handle cookies and redirections some login system uses.

The EASIEST way, in my opinion, is to download a free vb HTTP control somewhere, please google, or if another expert wants to suggest one, as I do not have the experience with any of them thats out there.
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
**Corrections, the POST message should be like below

POST /login.php HTTP/1.1
Host: http://www.test.com/
User-Agent: [WHATEVER CLIENT STRING]
Content-Length: [BYTE COUNT]
Content-Type: application/x-www-form-urlencoded  [MAYBE FORM-MULTIPART etc etc]

name=blah

0
 

Author Comment

by:Berhan Karagoez
Comment Utility

so basically I can make the form html which is a local file and then simply post the form to the correct url, no?!

0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
if the recieving end does not check for referer, then yeah.... that should work?

like if you just make a local html file:

<form method=POST action='http://www.test.com/login.php>
<input name=username>
</form>

and trigger the form action somehow... then yeah, it should work, but if you get a invalid referer or something then you will need another method
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
just to make your life easier, you can automatically submit a form by using:

javascript:document.FORMNAME.submit();

so just stick that into <body onload= or something xD

so:

FORM CODE
<body onload='javascript:document.MyForm.submit();'>

*please note this code is untested, i dont even know for sure if you can have a form before body, but i mean you can easily trigger that javascript code in the onload of many form elements
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
another note, just make sure your form has the same control names as the form you are imitating, eg if the actual thing has <input name='test1'>, you have to have the samething in your form, also for hidden elements(so read source code), and also you should still have that submit button there because its also a POST value of submit=submit.. if anything wants to use it..
0
 

Author Comment

by:Berhan Karagoez
Comment Utility
Yes, I am aware of most of the things said, what I really would like to know is :

HOW do I simulate user clicking on a drop down box and chosing a value from it and then submitting it.

I did with vb code (ie browser control) navigate to correct page, logged in automatically, ie filling login/pass and invoking submit from page, next thing to do is being able to choose a value from a drop down list and submitting it.

Maybe it can be done if referer is not checked that I make a html page that has the value of my preference in the dropdown box as default and I simply submit it, but then again it will not be 100% the real thing.

There has to be a way to do it.

/BK
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
well there is no need for simulating those you mentioned:

eg:

say your form has an drop down:

<select name="options1">
<option>blah</option>
<option>lol</option>
</select>

if you want to simulate the user clicking on the option blah, simply send the form with options1='blah'

as you can see these form elements are not handled like the event base system we get in VB.


0
 
LVL 10

Accepted Solution

by:
sakuya_su earned 500 total points
Comment Utility
to the recieving PHP scripts, theres no such thing as form elements, they are all posted as strings, so a form with a input named test1 and a option named test2 would be recieved on the server as:

test1=VALUE&test2=VALUE regardless of what control it was on the user's end
0
 

Author Comment

by:Berhan Karagoez
Comment Utility
can you wait for the reward till I test it? ;)

/BK
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
hehe not a problem, although i would like to have it in the next 2 3 days (3000 points a month and im er.. 200 short xD)

0
 

Author Comment

by:Berhan Karagoez
Comment Utility
Thanx, here you go, I'll test it later and if it doesn't work I'll write back! ;)
0
 
LVL 10

Expert Comment

by:sakuya_su
Comment Utility
thanks very much indeed, do let me know if anything is not working
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now