|
-
October 14th, 2009, 07:45 AM
#1
Web page interaction
Hi.
I'm trying to make an application which will log me into a site and read the text of the site and display a certain part of that text in my form.
I'm stuck at the login, its a .php page with 2 text boxes, 1 check box and 1 button.Is there any way to manipulate those objects by using controls in my form?
-
October 14th, 2009, 08:43 AM
#2
Re: Web page interaction
A WebBrowser component would be the best suited control for this purpose
-
October 14th, 2009, 08:57 AM
#3
Re: Web page interaction
I'm using it but cant figure out how to "WebBrowser1.TextBox1.Text = Me.TextBox1.text" :P
-
October 14th, 2009, 09:35 AM
#4
Re: Web page interaction
To obtain text from the WebPage itself, you would need to use the .DocumentText property of the WebBrowser control.
To get text from a TextBox on a webpage, you would need to know the ID / Name of that particular TextBox on the page. If you know that, you could use the GetElementById method to get the text within that textbox.
-
October 14th, 2009, 10:08 AM
#5
Re: Web page interaction
I did this to get the text from the page
Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Label1.Text = Me.WebBrowser1.Document.Body.InnerText
End Sub
the name of the textbox in the web page is "vb_login_password" and i need it to grab the text from the textbox in my form couse the webbrowser is visible = false
-
October 14th, 2009, 11:11 AM
#6
Re: Web page interaction
Then something like this would work for you :
Code:
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
Dim ValueOfControl = ControlToLookFor.GetAttribute("value")
TextBox1.Text = ValueOfControl
-
October 14th, 2009, 11:29 AM
#7
Re: Web page interaction
this gets the text from the web browser textbox and puts it in the form textbox, while i need it to get the text from the form textbox and put it in the web browser text box
-
October 14th, 2009, 11:38 AM
#8
Re: Web page interaction
Seems I misunderstood 
It is still the same principle, instead of using GetAttirbute, use SetAttribute, like so :
Code:
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
Dim ValueOfControl = ControlToLookFor.SetAttribute("value", TextBox1.text)
Is that what you wanted ¿
-
October 14th, 2009, 12:02 PM
#9
Re: Web page interaction
Code:
ControlToLookFor.SetAttribute("value", TextBox1.Text)
this part gives me an error
-
October 15th, 2009, 12:39 AM
#10
Re: Web page interaction
Sorry it has to be :
Code:
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
ControlToLookFor.SetAttribute("value", TextBox1.text) ' Or whatever your Form's textbox is named
Just took the previous code and modified, without reading it much - It happens
-
October 15th, 2009, 07:47 AM
#11
Re: Web page interaction
Awesome worked perfectly
now i have 1 button which does not have a name, this is the souce:
Code:
<input type="submit" class="button" value="Log in" tabindex="104" title="Title Text" accesskey="s" />
how do u click it when i click on the button in my form?
P.S. i know almost nothing about html
-
October 15th, 2009, 08:09 AM
#12
Re: Web page interaction
On second thought rather change that to :
Code:
<input type="submit" ID = "Submit" class="button" value="Log in" tabindex="104" title="Title Text" accesskey="s" />
As all browsers are not create equal...
Last edited by HanneSThEGreaT; October 15th, 2009 at 08:12 AM.
-
October 15th, 2009, 08:11 AM
#13
Re: Web page interaction
Well, it seems you have 2 options 
By default, the Submit button is the default button, meaning, when you press enter, it will also work, like an AcceptButton on your form. So, you could use :
Code:
SendKeys.Send("{ENTER}")
May not work though, as I understand, your browser is not "visible" ¿
Second option.
Use InvokeMember("Click"), like this :
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("submit")
ControlToLookFor.InvokeMember("click")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
After you have given your button an id, demonstrated in post #12
-
October 15th, 2009, 08:51 AM
#14
Re: Web page interaction
well the page isnt mine so i cant change the source.
so instead of making the browser "visible = false" ive located it outside the form so its visible , and made the form border stile Fixed3D so it cannot be expanded
and used this code
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PasswordField As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
PasswordField.Focus()
SendKeys.Send("{ENTER}")
End Sub
-
October 15th, 2009, 08:57 AM
#15
Re: Web page interaction
Good. I was under the impression this is your site & stuff 
You're not using this for malicious purposes are you ¿ LOL!
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
|