|
-
Dec 13th, 2008, 03:16 AM
#1
Thread Starter
Fanatic Member
WebBrowser Control
Hi,
Have a look at this page:-
http://webmail.vsnl.com/
I want to login to my VSNL account through VB using Web Browser Control. Is it possible?
How to fill the textboxes and click on login button using VB?
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 13th, 2008, 03:38 PM
#2
Fanatic Member
Re: WebBrowser Control
Sure - what's your username and password?
Just kidding, actually I do this to get information from my contractor's websites all time.
Code:
Sub getMail()
Dim ie As Object, wsh As Long, x As Object
Set ie = CreateObject("Internetexplorer.Application")
ie.navigate ("http://webmail.vsnl.com/")
While ie.busy: DoEvents: Wend
ie.Visible = True
While ie.busy: DoEvents: Wend
'your user id
ie.document.Forms(0).Elements("userid").Value = "user"
'your password
ie.document.Forms(0).Elements("password").Value = "password"
'your server
For Each x In ie.document.Forms(0).Elements("server").Options
If x.Value = "vsnl.com" Then x.Selected = True
Next
ie.document.Forms(0).submit
While ie.busy: DoEvents: Wend
msgbox "you're in!!!-click OK to close browser"
While ie.busy: DoEvents: Wend
ie.Quit
Set ie = Nothing
End Sub
Try this - note where I put comments for user name and password and server. If you study HTML Dom you could navigate the entire site. Remove the quit statement and the browser wont close.
http://www.w3schools.com/htmldom/default.asp
Last edited by technorobbo; Dec 13th, 2008 at 03:42 PM.
-
Dec 15th, 2008, 09:29 AM
#3
Thread Starter
Fanatic Member
Re: WebBrowser Control
Thanks for the code. Its showing invalid username or password. It was happening so fast. So I used camstudio to record and i found the user, sever and password was correct.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 15th, 2008, 09:35 AM
#4
Thread Starter
Fanatic Member
Re: WebBrowser Control
I have tried the code for yahoo. It worked.
PHP Code:
Dim i As Integer
Sub getMail()
Dim ie As Object, wsh As Long, x As Object
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://mail.yahoo.com")
While ie.Busy: DoEvents: Wend
ie.Visible = True
While ie.Busy: DoEvents: Wend
'your user id
ie.Document.Forms(0).Elements("login").Value = "username"
'your password
ie.Document.Forms(0).Elements("passwd").Value = "mypass"
While ie.Busy: DoEvents: Wend
ie.Document.Forms(0).submit
While ie.Busy: DoEvents: Wend
MsgBox "you're in!!!-click OK to close browser"
While ie.Busy: DoEvents: Wend
ie.Quit
Set ie = Nothing
End Sub
Private Sub Command1_Click()
Call getMail
End Sub
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 15th, 2008, 09:52 AM
#5
Thread Starter
Fanatic Member
Re: WebBrowser Control
Sometimes it gives error "Object variable not set or with block variable" in my yahoo mail code
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 15th, 2008, 11:11 AM
#6
Re: WebBrowser Control
On what line do you encounter the error?
-
Dec 16th, 2008, 01:07 AM
#7
Thread Starter
Fanatic Member
Re: WebBrowser Control
The following line:-
Code:
ie.Document.Forms(0).Elements("login").Value = user
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 16th, 2008, 01:15 AM
#8
Thread Starter
Fanatic Member
Re: WebBrowser Control
What does the error mean?
Though I have wrote "On Error Resume Next" line at the beginning of function. Now its fixed.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Dec 16th, 2008, 01:37 AM
#9
Re: WebBrowser Control
Could you try it like this? It will just check if it's state is ready.
Code:
Sub getMail()
Dim ie As Object
Dim wsh As Long
Dim x As Object
Const READYSTATE_COMPLETE = 4
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://mail.yahoo.com")
While ie.Busy
DoEvents
Wend
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ie.Visible = True
While ie.Busy
DoEvents
Wend
'your user id
ie.Document.Forms(0).Elements("login").Value = "username"
'your password
ie.Document.Forms(0).Elements("passwd").Value = "password"
While ie.Busy: DoEvents: Wend
ie.Document.Forms(0).submit
While ie.Busy: DoEvents: Wend
MsgBox "you're in!!!-click OK to close browser"
While ie.Busy: DoEvents: Wend
ie.Quit
Set ie = Nothing
End Sub
-
Jan 1st, 2009, 07:53 AM
#10
Thread Starter
Fanatic Member
Re: WebBrowser Control
Though your code is not giving error as before but it shows worng ID and password when i use it for webmail.vsnl.com
Upto filling the textbox its OK but when the submit code is executed then the webpage shows error but when i manually click the submit button then it logs in to my account.
I have also applied the timer but it was of no use.
Code:
Dim ie As Object
Public Function getMail()
Dim wsh As Long
Dim x As Object
Const READYSTATE_COMPLETE = 4
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://webmail.vsnl.com")
While ie.Busy
DoEvents
Wend
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ie.Visible = True
While ie.Busy
DoEvents
Wend
'your user id
ie.document.Forms(0).Elements("userid").Value = "MYID"
'your password
ie.document.Forms(0).Elements("password").Value = "MYPASS"
ie.document.Forms(0).Elements("server").Options.Value = "vsnl.net"
While ie.Busy: DoEvents: Wend
Timer1.Enabled = True
End Function
Private Sub Command1_Click()
Call getMail
End Sub
Private Sub Timer1_Timer()
ie.document.Forms(0).submit
Timer1.Enabled = False
End Sub
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 1st, 2009, 07:57 AM
#11
Thread Starter
Fanatic Member
Re: WebBrowser Control
Here are the screen-shots of the page after executing the program:-
By the way, HAPPY NEW YEAR!
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 1st, 2009, 08:10 AM
#12
Re: WebBrowser Control
What error is raised when you submit the form?
-
Jan 1st, 2009, 08:36 AM
#13
Thread Starter
Fanatic Member
Re: WebBrowser Control
Error is not raised. But when the submit is done through Program then it doesn't work. The webpage shows " Wrong User ID or Password ".(Though UserID and password is correct) When I manually click submit button then it works.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 1st, 2009, 08:40 AM
#14
Re: WebBrowser Control
How are you submitting programatically?
-
Jan 1st, 2009, 08:54 AM
#15
Thread Starter
Fanatic Member
Re: WebBrowser Control
ie.document.Forms(0).submit
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 2nd, 2009, 09:30 AM
#16
Fanatic Member
Re: WebBrowser Control
You can't set option value it must be and index!
incorrect:
Code:
ie.document.Forms(0).Elements("server").Options.Value = "vsnl.net"
correct:
Code:
For Each x In ie.document.Forms(0).Elements("server").Options
If x.Value = "vsnl.net" Then x.Selected = True
Next
-
Jan 2nd, 2009, 12:25 PM
#17
Thread Starter
Fanatic Member
Re: WebBrowser Control
@techno
No, Its selected. See the screen-shots posted above. I also tried your code, its selecting but again the webpage is throwing error.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 2nd, 2009, 04:08 PM
#18
Re: WebBrowser Control
Could you post all the relevant codes?
-
Jan 3rd, 2009, 06:51 AM
#19
Lively Member
Re: WebBrowser Control
How can i do it for vbforums.com ??? i tried the following code and it didn't work.
Code:
Dim i As Integer
Sub getMail()
Dim ie As Object, wsh As Long, x As Object
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://vbforums.com")
While ie.Busy: DoEvents: Wend
ie.Visible = True
While ie.Busy: DoEvents: Wend
'your user id
ie.Document.Forms(0).Elements("login").Value = "wiz...."
'your password
ie.Document.Forms(0).Elements("passwd").Value = "password"
While ie.Busy: DoEvents: Wend
ie.Document.Forms(0).submit
While ie.Busy: DoEvents: Wend
MsgBox "you're in!!!-click OK to close browser"
While ie.Busy: DoEvents: Wend
ie.Quit
Set ie = Nothing
End Sub
Private Sub Command1_Click()
Call getMail
End Sub
Last edited by wiz....; Jan 3rd, 2009 at 07:11 AM.
PAIN n SUFFERING-Pain is Inevitable,,suffering is optional...........
WORK EXPECTATION--U can do anything in this world if u don't look for credit.........
-
Jan 3rd, 2009, 07:12 AM
#20
-
Jan 3rd, 2009, 07:44 AM
#21
Thread Starter
Fanatic Member
Re: WebBrowser Control
Code:
Dim ie As Object
Public Function getMail()
Dim wsh As Long
Dim x As Object
Const READYSTATE_COMPLETE = 4
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://webmail.vsnl.com")
While ie.Busy
DoEvents
Wend
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ie.Visible = True
While ie.Busy
DoEvents
Wend
'your user id
ie.document.Forms(0).Elements("userid").Value = "avinternational"
'your password
ie.document.Forms(0).Elements("password").Value = "password"
For Each x In ie.document.Forms(0).Elements("server").Options
If x.Value = "vsnl.net" Then x.Selected = True
Next
While ie.Busy: DoEvents: Wend
Timer1.Enabled = True
End Function
Private Sub Command1_Click()
Call getMail
End Sub
Private Sub Timer1_Timer()
ie.document.Forms(0).submit
Timer1.Enabled = False
End Sub
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 3rd, 2009, 10:04 AM
#22
Thread Starter
Fanatic Member
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 3rd, 2009, 10:33 AM
#23
Re: WebBrowser Control
I am not sure what's wrong since I cannot test it fully without a valid username and password, of course I always get an 'invalid' error. Could it be that the form has a different index?
-
Jan 6th, 2009, 07:07 AM
#24
Fanatic Member
Re: WebBrowser Control
@Wiz
Each Webpage is different - so you have to examine the source.
In the case of VBforums the search form is first and the login is second. Also the Names of the controls are specific to the form, the correct code is below,
Make sure you logoff before trying to log in.
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim ie As Object, wsh As Long, x As Object
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://vbforums.com")
While ie.Busy: DoEvents: Wend
ie.Visible = True
While ie.Busy: DoEvents: Wend
'your user id
ie.Document.Forms(1).Elements("vb_login_username").Value = "youlogin"
'your password
ie.Document.Forms(1).Elements("vb_login_password").Value = "yourpassword"
While ie.Busy: DoEvents: Wend
ie.Document.Forms(1).submit
While ie.Busy: DoEvents: Wend
MsgBox "you're in!!!-click OK to close browser"
While ie.Busy: DoEvents: Wend
ie.Quit
Set ie = Nothing
End Sub
-
Jan 8th, 2009, 02:03 AM
#25
Thread Starter
Fanatic Member
Re: WebBrowser Control
@techno
You r right. In my case the code is absolutely correct. The webpage is filling up with correct values. Now i will give my user and pass to dee-u through private message.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 8th, 2009, 10:00 AM
#26
Thread Starter
Fanatic Member
Re: WebBrowser Control
Hey! Dee-U i have sent you the User and Pass for webmail.vsnl.com.
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 8th, 2009, 10:18 AM
#27
Re: WebBrowser Control
Cheers pal, here's how you will submit it. You can now change your password!
Code:
ie.document.All("Submit").Click
-
Jan 8th, 2009, 10:28 AM
#28
Thread Starter
Fanatic Member
Re: WebBrowser Control
Thanks. Actually now i am using MS-OUTLOOK but i just asked because i was curious to know.
Thanks very much.
How you identified it. Is it because of this code ?
<input name="Submit" type="submit" class="blue11b" value="Sign In" onclick="post();">
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 8th, 2009, 10:32 AM
#29
Thread Starter
Fanatic Member
Re: WebBrowser Control
I am making an application which Checks mail and also only shows No. of Yahoo Mails Total and Unread in a label.
I have successfully done that by using INET control and string handling function.
The only problem is that i want that the ie window should not be visible. Though i have set the boolean value to false but then also a window opens with this URL. Its only in case of yahoo webpage:-
http://search.yahoo.com/web?fr=ush1-mail
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 8th, 2009, 10:33 AM
#30
Thread Starter
Fanatic Member
Re: WebBrowser Control
Code:-
Code:
Sub getMail(v As Boolean)
On Error Resume Next
Dim ie As Object, wsh As Long, x As Object
Set ie = CreateObject("Internetexplorer.Application")
ie.Navigate ("http://mail.yahoo.com")
While ie.Busy
DoEvents
Wend
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ie.Visible = False
While ie.Busy
DoEvents
Wend
'your user id
ie.Document.Forms(0).Elements("login").Value = Text1.Text
'your password
ie.Document.Forms(0).Elements("passwd").Value = Text2.Text
While ie.Busy
DoEvents
Wend
ie.Document.Forms(0).submit
While ie.Busy: DoEvents: Wend
loc = ie.LocationURL
End Sub
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 8th, 2009, 10:38 AM
#31
Re: WebBrowser Control
Yes, that was my clue and tried it and it worked like a charm. If you are using INET then why are you still using IE? I could not understand what you meant, perhaps it needs another thread for such diversce concern.
-
Jan 9th, 2009, 05:54 AM
#32
Thread Starter
Fanatic Member
Re: WebBrowser Control
If you are using INET then why are you still using IE?
Actually i am using it to accomplish two different task. I know it can be done only by using INET but still i want to know the reason of the webpage that is opening. When the value is set to true then two window appears.
I want to know Why ?
Dont rely only on your luck. Work hard until You get success.
vb Code:
Private sub Time_ispassing
While Me.Notgetsuccess
trygain=tryagain+1
Me.workhard
wend
end sub
-
Jan 9th, 2009, 05:19 PM
#33
Re: WebBrowser Control
Not sure about the window that appears but instead of IE you can use your own WebBrowser which acts the same as IE.
-
Apr 19th, 2009, 02:29 PM
#34
Lively Member
Re: WebBrowser Control
 Originally Posted by technorobbo
'your user id
ie.Document.Forms(1).Elements("vb_login_username").Value = "youlogin"
'your password
ie.Document.Forms(1).Elements("vb_login_password").Value = "yourpassword"
While ie.Busy: DoEvents: Wend
ie.Document.Forms(1).submit
[/CODE]
Hi guys, I was looking at this thread and am able to reproduce the great advice given.
What I am interested in is that the opening of a form, entering information into the boxes and "clicking" on the submit seems old. I am a beginner so please forgive me when I am misunderstanding something here, but couldn't we just shorten the logon to a single URL or to what ever clicking on the Submit button does?
Isnt the "click" going to submit a url something like this?
Code:
www.whatever......php?vb_login_username=youlogin&vb_login_password=yourpassword
thus why cannot we just navigate directly to this in the first instance?
-
Apr 19th, 2009, 04:27 PM
#35
Fanatic Member
Re: WebBrowser Control
That would work in a "GET" Method form but not in a "POST" Method form.
Here's the W3 link
http://www.w3.org/MarkUp/html-spec/h..._8.html#SEC8.2
Last edited by technorobbo; Apr 19th, 2009 at 04:30 PM.
-
Apr 19th, 2009, 07:20 PM
#36
Lively Member
Re: WebBrowser Control
Thanks for replying.
I am actually doing some googling on it right now. seems I have this
http://www.developerfusion.com/artic...-a-web-page/2/
I am actually looking at POST
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|