Link to home
Start Free TrialLog in
Avatar of mikekwok
mikekwokFlag for Hong Kong

asked on

writing a program to insert text in a form and click "submit" button in a browser (IE or Netscape)?

I would like to ask is there any reference and source code on writing a program to insert text in textfield in a form and click "submit" button in a browser (IE or netscape)? What programming tools can I do so ?
Avatar of itaLix
itaLix

Well this question has a lot of answers, because of the different programming languages you can use.

If you have the .NET Framework,

I'll give you an example how to do this if you have .NET and an IIS server enabled on your computer.

----
Copy from here on...
------------------------

<%@ Page Language="VB" %>
<script runat="server">
   Sub Page_Load(sender as Object, e As EventArgs)
      TextBox1.Text = "Hello"
       ButtonClick() 'This right here goes to the Routine that your Button uses, so this is essentially as clicking the button.
   End Sub

   Sub Button1_Click(sender as Ojbect, e As EventArgs)
       ButtonClick()
   End Sub

   Sub ButtonClick()
      'Do what you want to do when your button is clicked, you didn't really say what you wanted to do.
   End Sub
</script>

<html>
<body>
<form runat="server">

<asp:textBox id="TextBox1" runat="server" />
<br>
<asp:Button id="Button1" OnClick="Button1_Click" runat="server" Text="Submit" />

</form>
</body>
</html>


----------

Here is a code that you can copy and paste and then modify out of this what you actually need.
This code accomplished what you asked, to insert the text in a textbox and then it clicked submit buttong, although I may be interpretting that too literally and you just wanted a submit button. Which in that case you'd just take out the ButtonClick() line out of your PageLoad routine.

hope that helps you.

.itaLix
To add to my comment, you will need a textpad, or the ASP.NET Web Matrix,  an IIS server (which comes with XP Pro) and just save this text file that contains the code that I wrote above as an .ASPX file, as such (Test.aspx).

then I'd put this in your wwwroot folder which is created when you install/enable your IIS server.

Then in your webbrowser type in http://localhost/Test.aspx

and your page should appear.

To get the free ASP.NET Web Matrix just go here <a href="www.asp.net">asp.net</a> and download it. Its a great free tool.

.itaLix
Avatar of mikekwok

ASKER

My situation is that the Web server is not hosted in my computer . I can only write a program to insert the text in a textfield in a form in a browser and then using my program to click the submit button ........


That mean : a user uses my program, and open a browser in his computer, he has typed in the URL that has a form inside . Then he uses my program and type a text in my program, he then clicks a button in my program and that text which is typed in my program will send to textfield in the browser that he opened.

Can your sourcecode suit my problem ?
i understand that your form is in asp.

ur this asp form takes the field as quesrystring
then in your vb program u can do sumthign like this...

on button click
u can call the url concatenated with the text1.text..

Did you understannd what i said..

If you need more help do tell me...But plzz confirm you want to do simthg like this only..
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
  Like this?  

<html><head>
<script>
function doit(formObj)
{
  formObj.b.value = 'Bye Bye!!!';
  formObj.action = 'somepage.html'
  formObj.submit();
}
</script>
</head>
<body onload='doit(document.a)'>
<form name='a'>
<input type='text' name='b'>
</form>
</body>
</html>

Vinny
CEHJ, would you please tell how how to use the httpunit ? would u give me an example on using it ?
I have already solved the problem using Visual Basic with Internet Explorer Object . I access the DOM structure of the Internet Explorer Object and simulate clicking buttons, entering texts  in the textfield , etc.
Go ahead and close the question then. Thanks.
After I login to a homepage, it pop up a dialog : "Secure Information. This Page contains both secure and non-secure items. Do you want to display the non-secure items ?"
my current approach to solve this problem is to use AppActivate "Security Information" and then press enter using the keysboard event.

Would somebody tell me how can i know when the secure information dialog s pop up and then i do something after pop u p?
would you tell me how to change security settings at IE configuration so that the security information dialog will not pop up ?
Also,If there are 2 frames in a homepage, how can it detect if the content of 1 of the frames finish loading in Visual Basic ?
I don't know how can i set an IE object reference to the Internet Explorer which is opened by another Internet Explorer ?

My situation is that after clicking a button in Internet Explorer, it popup some IE . i need to locate all those IE and click something in the IE.
would somebody please help me ?
8-)

You probably need the EnumWindows/EnumWindowsEx API to start with. Post a q in one of the windows development TAs