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.

Member Avatar for iamthwee

vb.net sendkeys perhaps?

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?

Member Avatar for iamthwee

I don't know, maybe this?

Select Case e.KeyCode
                Case Keys.Down
                    SendKeys.Send("{Tab}")

                Case Keys.Up
                    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.

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
Member Avatar for iamthwee

Cheers, how's the wma -> mp3 convertor coming along?

yeah... we just won't go there.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.