| | |
Entering text into existing webform
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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.
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.
Insert generic signature here
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
http://www.exefind.com/sendkeys-repl...ic-P21707.html
Hope you're not using ie7
*Voted best profile in the world*
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?
Insert generic signature here
I don't know, maybe this?
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.
VB.NET Syntax (Toggle Plain Text)
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.
Last edited by iamthwee; Nov 12th, 2006 at 9:12 am.
*Voted best profile in the world*
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.
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
Insert generic signature here
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?
Insert generic signature here
![]() |
Similar Threads
- text messaging WT??? (Cellphones, PDAs and Handheld Devices)
Other Threads in the VB.NET Forum
- Previous Thread: I need to be able to hit Enter as well as clicking button.
- Next Thread: VB3 to .net?
Views: 4605 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date design designer dissertation dissertations dropdownlist excel fade file-dialog ftp generatetags google gridview hardcopy images inline input insert installer intel internet listview mobile monitor ms net networking objects output passingparameters picturebox picturebox1 port print printing problem project remove save searchbox searchvb.net select serial server shutdown soap sorting studio survey syntax table tcp temperature text textbox time timer toolbox trim update updown user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web winforms wpf






