|
-
Jan 18th, 2009, 02:47 PM
#1
Thread Starter
New Member
[RESOLVED] How to login to website using WebBrowser component?
I want to make program that will login to phpbb3 forum...
And I want to use WebBrowser component... but I dont know how to login to forum using it...
-
Jan 18th, 2009, 04:47 PM
#2
Re: How to login to website using WebBrowser component?
Search these forums, there are loads of examples of people asking the exact same thing.
-
Jan 18th, 2009, 06:18 PM
#3
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Well I did some researches here but here is the thing...
I setup a browser and command button for design... and here is the code:
Code:
Private Sub command1_click()
Dim ie As WebBrowser
ie.Navigate ("http://forumurl.com/ucp.php?mode=login")
ie.Document.Forms(0).Elements("username").Value = "stefo"
ie.Document.Forms(0).Elements("password").Value = "pass"
ie.Document.Forms(0).submit
MsgBox "you're in!!!-click OK to close browser"
End Sub
I get error: "Object variable or With block variable not set"
Last edited by stefo911; Jan 19th, 2009 at 04:29 AM.
-
Jan 18th, 2009, 07:58 PM
#4
Re: How to login to website using WebBrowser component?
You have to wait until your browser has actually loaded the page. Your telling it to navigate to that website and then instantly asking it to enter text into some textboxes that wont even be there yet.
You should drag an instance of the WebBrowser control onto your form and then place this code (minus the declaring bit obviously as you would already have a webbrowser there now) in the LoadComplete event (or whatever its called).
-
Jan 19th, 2009, 04:29 AM
#5
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Like this:
Code:
Private Sub command1_click()
Dim ie As WebBrowser
ie.Navigate ("http://forumurl.com/ucp.php?mode=login")
End Sub
private sub WebBrowser1_DocumentCompleted()
ie.Document.Forms(0).Elements("username").Value = "stefo"
ie.Document.Forms(0).Elements("password").Value = "pass"
ie.Document.Forms(0).submit
MsgBox "you're in!!!-click OK to close browser"
end sub
Didn't tried this but I assume it's something like this?
-
Jan 19th, 2009, 05:49 AM
#6
Re: How to login to website using WebBrowser component?
Yeah very similar to that
-
Jan 19th, 2009, 06:13 AM
#7
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
It doesn't work. It navigates me to the page but it wont log me in.
-
Jan 19th, 2009, 06:28 AM
#8
Re: How to login to website using WebBrowser component?
Are you sure your text fields on the website are named "username" and "password" ?
Also, you may need to set the OuterText (or might be InnerText, cant remember) properties instead of the Value
-
Jan 19th, 2009, 03:26 PM
#9
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Well I want to login to the phpBB3 forum so I'm sure fields are username & password.
-
Jan 19th, 2009, 03:33 PM
#10
Re: How to login to website using WebBrowser component?
This thread could provide valuable hints.
-
Jan 19th, 2009, 05:15 PM
#11
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
I tried it,it navigates me to the page but it doesn't log me in...
-
Jan 19th, 2009, 05:21 PM
#12
Re: How to login to website using WebBrowser component?
Does it raise an error? Perhaps those elements are locate in a different form.
-
Jan 19th, 2009, 05:24 PM
#13
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Hey I got it finally...
I modified code from the page you gave me...
Code:
Dim i As Integer
Sub getMail()
ie.Navigate ("http://forum.org/ucp.php?mode=login")
While ie.Busy: DoEvents: Wend
ie.Visible = True
While ie.Busy: DoEvents: Wend
'your user id
' ie.document.Forms(0).Elements("username").Value = "user"
'your password
'ie.document.Forms(0).Elements("password").Value = "pass"
ie.document.All("username").Value = "stefo"
ie.document.All("password").Value = "nissano19"
While ie.Busy: DoEvents: Wend
' ie.Document.Forms(0).submit
ie.document.All("Login").Click
While ie.Busy: DoEvents: Wend
MsgBox "you're in!!!-click OK to close browser"
End Sub
Private Sub Command1_Click()
Call getMail
End Sub
-
Jan 19th, 2009, 05:35 PM
#14
Re: How to login to website using WebBrowser component?
Good to hear that. You may now mark your thread as Resolved by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see it and know that you appreciate their help.
-
Jan 19th, 2009, 05:42 PM
#15
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Just one more question... does anybody know how to check if some strings exists on the website that webbrowser component loaded?
For example,I logged into website through VB but when I do it again it says Object .... With variable block set bla bla... something like that... so I figured why wouldn't I check if page has the word Logout... if it does then app shouldn't login but if it doesn't contains word Logout then it would log the user in...
And also,how to get content of some field? Cause I want to take content from the field message on forum that I have previously logged in...
I would like if you would be able to answer me first question,second question isn't that important to me....
-
Jan 19th, 2009, 06:24 PM
#16
Re: How to login to website using WebBrowser component?
You can get the entire HTML source of the website your browser is displaying by using the DocumentText property so you might be able to just use IndexOf or a RegEx query to see if the word Logout exists in that string.
-
Jan 19th, 2009, 06:37 PM
#17
Thread Starter
New Member
Re: How to login to website using WebBrowser component?
Okay,thanks will give it a shot.
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
|