i want to fill up the userID and password fields of the yahoo mail login page with the click of a button on the form but just cant get it right.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

WebBrowser1.Navigate("https://login.yahoo.com/config/login_verify2?.intl=sg&.src=ym")

Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick

WebBrowser1.Focus()
SendKeys.SendWait("userID")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("password")
SendKeys.SendWait("{Enter}")


it just skips the yahooID field and fills out the password field. what is wrong or is there a better way of doing it?

Recommended Answers

All 2 Replies

Eah, I'm not sure how long SendWait waits, but when I did this type of thing in visual basic 6, I had to add sleeps after every sendkeys event... I also had to add doevents (app.doevents). Even then, it never worked 100% correctly. It has been my years of experience (doing this type of thing for like 14 years) that using sendkeys NEVER behaves the way you want it to. Even if you get it right 90% of the time, some kind of fluctuation in the processor, it would send data to the wrong window. Even if the user simply accidentally clicks say, the desktop.... or an instant message pops up, etc, etc. Basically there is absolutely no fault tolerance with Sendkeys.

That said, you might want to manually follow the steps, to make sure that say, the username box gets the focus on the page immediately. What I mean is, perhaps since the page is built into the app, maybe "userid" isn't the textbox with focus.... so, load up your app, and watch..... if the userID /DOES/ get focus, then maybe you are sending the userID data too soon (ie: javascript in the web-page sets the focus to the textbox... if the page is loading, and has not yet run that javascript, then the username box won't have focus, and you'll skip right over it. [See what I mean about fault tolerance?]. Maybe try adding a sleep right after WebBrowser1.Focus(). Let me know if that helps it.

First, this is Visual Basic 4 / 5 / 6 i.e. classic VB forum. You're question is about VB.NET which has it's own forum here in DaniWeb.

WebBrowser1.Focus() sets the focus to the webbrowser control but there's no guarantee where the focus is in the web page its displaying.

Anyway, I got following key sequence to work:

WebBrowser1.Focus()
SendKeys.SendWait("+{TAB}") ' Tab back one step
SendKeys.SendWait("{TAB}") ' Tab forward one step
SendKeys.SendWait("userID")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("password")
SendKeys.SendWait("{Enter}")
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.