Need Help!

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
13 posts Page 1 of 2
Contributors
User avatar
Master M1nd
Top Poster
Top Poster
Posts: 82
Joined: Thu Aug 15, 2013 7:51 pm

Need Help!
Master M1nd
Hello Friends, | ASSLAM-O-ALAIKUM

Dear brothers/sisters, as i have discussed that I'm new in vb and that's why i need help. Some days ago i was watching a video on youtube about how to make a website login. In that video he uses yahoo login page. and i think i will also create for a website. and i start working on that. That tutorial was good and something like this :-

He add 2 Textboxes for username and password
Two Labels
A Web browser
2 Buttons ( LOGIN | NAVIGATE ) [ Well he make navigate button so that the person who is using that program should click on Navigate button to Open the site, But i didn't use it and use this in Form webbrowser1.navigate (" http://www.site.com " )

Well It was easy after watching his tutorial but one thing in which I was stucked is that he go to yahoo's Login Page and View it's source and find a code so that he can use it so that you don't need to click on the login button after typing username and password it will automatically log in when you will press login button on your program!

He do this
Code: Select all
webbrowser1.getelementbyid(".save").invokemember ("click")
Well the code he found from yahoo login source code is that .save which will automatically log in when the user will click on Log in button
but when i try to found for a site which was a forum actually a phbb forum and i found one too it was not .save it was login
and i use that in it but it do not work i try some other that were present in the site's source like sid etc but that were also not working.
That was my site's Code
Image
I use redirect - login - sid
but it didn't work with any of them

For Better understanding what I'm actually trying to ask you can see that same video!
http://www.youtube.com/watch?v=9EJXzWasTq4



Please Help me what should i use now instead of that code so my program also works like that one!
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Need Help!
comathi
Hello,

The reason why your code does not work is because "login" is not the ID of your element, but rather it's name. Whereas IDs are supposed to be unique to each element, more than one element can have the same name.

To get a list of all the elements with a given name, you can use this:
Code: Select all
loginButtons = WebBrowser1.GetElementsByName("login")
Now, assuming you have only one element with the name "login" on that page, or that the first one to appear is the correct login button, you can use the following code to invoke a click on it:
Code: Select all
loginButtons(0).invokemember ("click")
Since we're assuming that you want to use the first element of the list (which means the index is 0), this should perform a click on your login button cooll;
User avatar
Master M1nd
Top Poster
Top Poster
Posts: 82
Joined: Thu Aug 15, 2013 7:51 pm

Re: Need Help!
Master M1nd
i will try when i will come from my pc! thanks for replying bro :)
User avatar
Master M1nd
Top Poster
Top Poster
Posts: 82
Joined: Thu Aug 15, 2013 7:51 pm

Re: Need Help!
Master M1nd
But How to find the id of that login button in that html? omg;
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Need Help!
comathi
In this case, the author of the page did not set an ID for the login button element. This is totally up to the page's creator and is not required. That's why in this case we need to get the element by name.
User avatar
Smiley
VIP - Donator
VIP - Donator
Posts: 269
Joined: Sat Dec 19, 2009 3:39 pm

Re: Need Help!
Smiley
Hi Master M1nd

Since theirs no element id here is a method of finding elements by their class, i edited the code for the html page you have shown.
Code: Select all
 Dim elements As HtmlElementCollection = WebBrowser1.Document.All
        For Each element As HtmlElement In elements
            If element.GetAttribute("classname").Contains ("button1") Then
                element.InvokeMember("click")
            End If
        Next
Hope this helps, Smiley cooll;
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Need Help!
comathi
#Smiley

This does essentially the same thing as I posted, but it requires you to change the page source (the page might not be his) and it iterates over ALL of the elements in the page, not just those with the specified name.
User avatar
Smiley
VIP - Donator
VIP - Donator
Posts: 269
Joined: Sat Dec 19, 2009 3:39 pm

Re: Need Help!
Smiley
comathi wrote:
#Smiley

This does essentially the same thing as I posted, but it requires you to change the page source (the page might not be his) and it iterates over ALL of the elements in the page, not just those with the specified name.
Oops i didnt read every reply, dont i look like a fool LOL idoit;
User avatar
Master M1nd
Top Poster
Top Poster
Posts: 82
Joined: Thu Aug 15, 2013 7:51 pm

Re: Need Help!
Master M1nd
hmm I'm not the creator but the one who manages the forum is my friend. But he also didn't design that template!

Well Now what should i do? Any other way to get the id cryer;
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Need Help!
comathi
You can't get the ID if there's no ID to get lol.

You could always ask your friend to add an ID to that button, and then use the getElementById method, or you could use either what I or Smiley have posted, as both of these will work for your specific case cooll;
13 posts Page 1 of 2
Return to “Coding Help & Support”