Results 1 to 10 of 10

Thread: My first question!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    5

    Exclamation My first question!

    Hi all!

    I'm trying to make an automatic login in my program but it isn't working properly.

    The code I'm using to set the email value is this:
    Code:
    WebBrowser1.Document.GetElementById("email").SetAttribute("value,", ID)
    Whenever I inspect element of the email box on the website it says this:
    Code:
    <input class="textbox" type="email" name="email">
    Whenever I press login, it doesn't add the email text to the email box on the website. Why is this? I tried looking for the ID of the email box but I couldn't find it anywhere.

    Please help!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: My first question!

    Welcome to VBForums. I guess you were a bit excited about your first post but it is important that you provide meaningful titles for your threads. For those of us who spend a lot of time here, threads with titles that don't indicate the topic of the thread mean we have to open it to see what it's about, wasting our time if it's not relevant to us.

    As for your issue, you're calling GetElementById so you can only get an element by `id`. That element has no `id` attribute so it can't be gotten that way. You'll need to call GetElementsByName and get the element by the `name` attribute. Note that GetElementsByName returns a collection of elements because `name` may not be unique. You'll have to pick out the one you want. If there's only one match then it will always be the first item.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    5

    Re: My first question!

    Quote Originally Posted by jmcilhinney View Post
    Welcome to VBForums. I guess you were a bit excited about your first post but it is important that you provide meaningful titles for your threads. For those of us who spend a lot of time here, threads with titles that don't indicate the topic of the thread mean we have to open it to see what it's about, wasting our time if it's not relevant to us.

    As for your issue, you're calling GetElementById so you can only get an element by `id`. That element has no `id` attribute so it can't be gotten that way. You'll need to call GetElementsByName and get the element by the `name` attribute. Note that GetElementsByName returns a collection of elements because `name` may not be unique. You'll have to pick out the one you want. If there's only one match then it will always be the first item.
    Code:
    WebBrowser1.Document.GetElementById("email").SetAttribute("value,", ID)
    Doesn't work because no text appears in the email textbox.


    Code:
    WebBrowser1.Document.GetElementsByTagName("email").SetAttribute("value,", ID)
    Doesn't work because "'SetAttribute' is not a member of 'System.Windows.Forms.HtmlElementCollection'."



    Code:
    WebBrowser1.Document.GetElementsByTagName("email").GetElementsByName("value,", ID)
    Doesn't work because "Too many arguments to 'Public Function GetElementsByName(name As String) As System.Windows.Forms.HtmlElementCollection'."



    How do I use GetElementsByName? I'm quite new to VB.NET so be gentle.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: My first question!

    It's like you read this part:
    Quote Originally Posted by jmcilhinney View Post
    As for your issue, you're calling GetElementById so you can only get an element by `id`. That element has no `id` attribute so it can't be gotten that way. You'll need to call GetElementsByName and get the element by the `name` attribute.
    and then ignored this part:
    Quote Originally Posted by jmcilhinney View Post
    Note that GetElementsByName returns a collection of elements because `name` may not be unique. You'll have to pick out the one you want. If there's only one match then it will always be the first item.
    You're not picking out the one you want so why would you expect it to work? Is there only one match? If so then you know you have to get the first item from the collection. I'm guessing that, if you look, you can find out on the web how to get the first item from a collection in VB.NET, assuming that you don't already know. That's what you should be doing in the first place. If someone says "do this thing" and you aren't sure how to do that thing then the first thing you do is try to find out for yourself how to do that thing. If someone points you in a direction then go in that direction and stop when you either get to your destination or can't go any further. If you can't go any further, that's when you ask for more help. In short, look first and ask questions later.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    5

    Re: My first question!

    Quote Originally Posted by jmcilhinney View Post
    It's like you read this part:
    and then ignored this part:

    You're not picking out the one you want so why would you expect it to work? Is there only one match? If so then you know you have to get the first item from the collection. I'm guessing that, if you look, you can find out on the web how to get the first item from a collection in VB.NET, assuming that you don't already know. That's what you should be doing in the first place. If someone says "do this thing" and you aren't sure how to do that thing then the first thing you do is try to find out for yourself how to do that thing. If someone points you in a direction then go in that direction and stop when you either get to your destination or can't go any further. If you can't go any further, that's when you ask for more help. In short, look first and ask questions later.
    I messed around for a bit and the only thing I could come up with is:

    Code:
            Dim Elems As HtmlElementCollection
    
            Elems = WebBrowser1.Document.GetElementsByTagName("email")
    
            For Each elem As HtmlElement In Elems
                Dim nameValue As String = elem.GetAttribute("name")
                If nameValue.ToLower().Equals("email") Then
                    elem.SetAttribute("value,", ID & "@hotmail.com")
                End If
            Next
    AAAAAAAAnndd.... It doesn't work. I don't know what to do or how to do it. Is there a better way of finding a textbox and putting text into it?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: My first question!

    How do you get an item from a collection? By specifying its index. What's the index of the first item in a collection. Zero. So, get the item at index zero in the collection and call SetAttribute on it.

    You might also want to use the correct name of the attribute you're trying to set.

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    5

    Re: My first question!

    Quote Originally Posted by jmcilhinney View Post
    How do you get an item from a collection? By specifying its index. What's the index of the first item in a collection. Zero. So, get the item at index zero in the collection and call SetAttribute on it.

    You might also want to use the correct name of the attribute you're trying to set.
    I don't understand any of what you just said.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: My first question!

    You really should take the time to read a beginners tutorial instead of jumping in and asking others to explain the fundamentals to you along the way. There's a link in my signature below to a good one. Chapter 7 is about arrays and shows you how to index an array to get an element. Indexing a collection to get an item is the same, which is the point.

    As for the name of the attribute you're setting, let's go back to your first post:
    Quote Originally Posted by JohnCenaFan36 View Post
    Hi all!

    I'm trying to make an automatic login in my program but it isn't working properly.

    The code I'm using to set the email value is this:
    Code:
    WebBrowser1.Document.GetElementById("email").SetAttribute("value,", ID)
    Whenever I inspect element of the email box on the website it says this:
    Code:
    <input class="textbox" type="email" name="email">
    Whenever I press login, it doesn't add the email text to the email box on the website. Why is this? I tried looking for the ID of the email box but I couldn't find it anywhere.

    Please help!
    Does an HTML element have an attribute named "value,"? Where exactly did that comma come from?

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    5

    Re: My first question!

    Quote Originally Posted by jmcilhinney View Post
    You really should take the time to read a beginners tutorial instead of jumping in and asking others to explain the fundamentals to you along the way. There's a link in my signature below to a good one. Chapter 7 is about arrays and shows you how to index an array to get an element. Indexing a collection to get an item is the same, which is the point.

    As for the name of the attribute you're setting, let's go back to your first postoes an HTML element have an attribute named "value,"? Where exactly did that comma come from?
    That was a spelling mistake and OK I'll check out the tutorials, thanks!

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: My first question!

    Quote Originally Posted by JohnCenaFan36 View Post
    That was a spelling mistake and OK I'll check out the tutorials, thanks!
    You'll learn quite a bit from that tutorial, which is why I prefer to direct you there rather than solve this one problem and then see you back over and over with questions about lots of basic things, which is a waste of your time as well as ours. That tutorial is one of the better ones for beginners.

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