943,938 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 5987
  • VB.NET RSS
Nov 10th, 2006
0

Entering text into existing webform

Expand Post »
Hi all.

I am building an automated login program for my work scheduler (which is a website already existing online). I have created a form with a timer, that when the computers system time reaches a certain time, another form containing a web browser control launches and goes to the login page of my website. There are two text entry boxes and a submit button on this webpage(online site, not a .NET form), how do i code my program to enter in "username" in box 1, and "password" in box 2, and when finished, press the submit button. Keep in mind that I am launching a website within a windows form and the textboxes exist on that website, not on the form.

P.S. When the site loads, the cursor is already focused on the username box, the next "tab" would take it to the "password" focus, and another "tab" would focus the submit button. So that might help some.

Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ChadW is offline Offline
42 posts
since Oct 2006
Nov 11th, 2006
0

Re: Entering text into existing webform

vb.net sendkeys perhaps?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 11th, 2006
0

Re: Entering text into existing webform

Although whilst reading up on this, I came across the following horror article:

http://www.exefind.com/sendkeys-repl...ic-P21707.html

Hope you're not using ie7
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 11th, 2006
0

Re: Entering text into existing webform

Sendkeys. seems to work, with a few oddities. For whatever reason, the first character seems to get ignored (easily "fixed" by adding a sacrificial character in front). When I used the sendkeys.send(keys.tab) it enters a "9" in the first box (at the end of the first string) instead of tabbing to the next field. Any ideas?
Reputation Points: 10
Solved Threads: 0
Light Poster
ChadW is offline Offline
42 posts
since Oct 2006
Nov 12th, 2006
0

Re: Entering text into existing webform

I don't know, maybe this?

VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Select Case e.KeyCode
  3. Case Keys.Down
  4. SendKeys.Send("{Tab}")
  5.  
  6. Case Keys.Up
  7. SendKeys.Send("+{Tab}")

However, this would not be supported in ie7. So the only reliable way for VB programers to send keys in the future will be to use the Windows API and keybd_event.
Last edited by iamthwee; Nov 12th, 2006 at 9:12 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 14th, 2006
0

Re: Entering text into existing webform

For those interested in what the final solution was, here is the setup.

1 form, 2 labels, 2 timers, 1 webbrowser control

The webbrowser control had its property "URL" set to the website in question. Timer1 and Label1 were there for visual cues to the first part of the login, Timer2 and Label2 again are visual cues for the second part of the automated login. I'm sure there are different ways of doing this, but it works for me. :cheesy:

Webbrowser1 and Timer1/Label1 are running at form load. Label1 shows the TimeofDay, webbrowser1's URL (set in properties) has the login page loaded and waiting. There is no menu/tool strip, just the labels across the top of the form, and the webbrowser control filling the remainder of the form (640x480 in my setup).

When TimeofDay hits the set-time in the first IF/THEN statement, timer1 is shut off BEFORE sending the sendkeys.send("usernamehere") command. Why? Well, in this configuration, it would repeat the "usernamehere" string every time the timer ticked until the textbox was filled. No good. Shutting of the timer before the sendkeys command solved this. A "Tab" command was sent (thanks for the tip iamthwee) to move the cursor focus to the password field, and then the sendkeys command types out the password, the next sendkeys sends an ENTER command to submit the login, as well as activating timer2.

In the Timer2 set, timer2 is shut off once the timeofday in the IF/THEN is reached. (I purposely added a long delay, 2mins 10secs, to account for *any* conceivable delays in page loads). In my situation, the second page has a "confirm" button that needs to be pressed in order to finalize the login, so two Tabs brings focus to the correct button and an ENTER submits the confirmation.

Obviously, the code below will only work for the particular site that I am using, but I'm sure with some experimentation, and counting of "TABS" you can make it work for your use. Enjoy.

PublicClass Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
Timer1.Enabled = True
Timer2.Enabled = False
 
End Sub
 
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
 
Label1.Text = TimeOfDay
 
If TimeOfDay = "5:30:10 PM" Then
Timer1.Enabled = False
SendKeys.Send("usernamehere")
SendKeys.Send("{TAB}")
SendKeys.Send("passwordhere")
SendKeys.Send("{ENTER}")
Timer2.Enabled = True
End If
 
End Sub
 
Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
 
Label2.Text = TimeOfDay
 
If TimeOfDay = "5:32:20 PM" Then
Timer2.Enabled = False
SendKeys.Send("{TAB}")
SendKeys.Send("{TAB}")
SendKeys.Send("{ENTER}")
End If
 
End Sub
 
EndClass
Reputation Points: 10
Solved Threads: 0
Light Poster
ChadW is offline Offline
42 posts
since Oct 2006
Nov 14th, 2006
0

Re: Entering text into existing webform

Cheers, how's the wma -> mp3 convertor coming along?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 14th, 2006
0

Re: Entering text into existing webform

yeah... we just won't go there.
Reputation Points: 10
Solved Threads: 0
Light Poster
ChadW is offline Offline
42 posts
since Oct 2006
Nov 24th, 2006
0

Re: Entering text into existing webform

Something I've noticed when using a webbrowser control is that for some reason if I highlight a textbox that already has text in it, in order to change that text to something else (i.e. changing a numeric value) it almost acts like the program doesn't see the keyboard. However, if I just backspace/delete the existing text and retype the new text, its fine. Anyone else encounter this?
Reputation Points: 10
Solved Threads: 0
Light Poster
ChadW is offline Offline
42 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: I need to be able to hit Enter as well as clicking button.
Next Thread in VB.NET Forum Timeline: VB3 to .net?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC