Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

html submit automatically.

Posted on 2006-11-28
15
Medium Priority
?
600 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
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
Technology Partners: 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!

 
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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 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