CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Oct 2009
    Posts
    16

    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?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Web page interaction

    A WebBrowser component would be the best suited control for this purpose

  3. #3
    Join Date
    Oct 2009
    Posts
    16

    Re: Web page interaction

    I'm using it but cant figure out how to "WebBrowser1.TextBox1.Text = Me.TextBox1.text" :P

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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.

  5. #5
    Join Date
    Oct 2009
    Posts
    16

    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

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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

  7. #7
    Join Date
    Oct 2009
    Posts
    16

    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

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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 ¿

  9. #9
    Join Date
    Oct 2009
    Posts
    16

    Re: Web page interaction

    Code:
    ControlToLookFor.SetAttribute("value", TextBox1.Text)
    this part gives me an error

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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

  11. #11
    Join Date
    Oct 2009
    Posts
    16

    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

  12. #12
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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.

  13. #13
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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" &#191;

    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

  14. #14
    Join Date
    Oct 2009
    Posts
    16

    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

  15. #15
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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 &#191; LOL!

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured