Solved

html submit automatically.

Posted on 2006-11-28
15
593 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
[X]
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
  • 9
  • 5
15 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 18032565
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
ID: 18032615
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
ID: 18033709
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 10

Expert Comment

by:sakuya_su
ID: 18033717
**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
ID: 18036013

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
ID: 18036060
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
ID: 18036074
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
 
LVL 10

Expert Comment

by:sakuya_su
ID: 18036082
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
ID: 18036104
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
ID: 18036795
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
ID: 18036824
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
ID: 18041435
can you wait for the reward till I test it? ;)

/BK
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 18042588
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
ID: 18043718
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
ID: 18044213
thanks very much indeed, do let me know if anything is not working
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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