Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I am looking to make a log in form that enters the text that you type in the email and password and then press enter on the log in button. The problem I had the log in button doesn't have an ID for me to use GetElementById. Here is a screenshot of inspect element screen.
 
http://gyazo.com/3c30fcafe5a55ff42f2f9b809f65a3cf[^]
Posted 10-Feb-13 19:24pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The add the ID! Or do you expect it will be added by itself? Smile | :)
 
[EDIT]
 
Thank you for clarification.
 
Please see my comments below.
 
You do not have to fill in the form, it won't give you anything. And id won't help you at all. You need to send HTTP request the way the form does. To do that, you need to use System.Net.HttpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].
 
Basically, the records of the HTTP request data block are identified by the attributes name of the form input elements, not id. You need to either lean some basics of HTTP or spy on what client does using some TCP/IP spy software.
 
—SA
  Permalink  
v2
Comments
Zack McIntosh at 11-Feb-13 12:14pm
   
I didn't make the website so how can I add an id to the button?
Sergey Alexandrovich Kryukov at 11-Feb-13 12:40pm
   
OK, it's not yours? From your question, it wasn't clear at all. Normally, if you need id, you generated it, how else?
In this case, why would you need ID? I don't know your goals now, but if this is some kind of Web scraping, no matter how you do it, you would need to parse HTML. You always should start your questions with explanation of your ultimate goals. If you do, you might get further help...
—SA
Zack McIntosh at 11-Feb-13 12:52pm
   
My ultimate goal is to be able to log in from the form instead of having to log in at the website. It's as simple as that. I already have the code to enter the text from the form's textboxes to the webbrowsers1's textboxes but I can't do the button since it has no ID. If I were able to edit the HTML, how could I ad an ID? Just go to it and add id="somecrap" ?
Sergey Alexandrovich Kryukov at 11-Feb-13 14:37pm
   
Understood. You can do it, but the approach should be totally different. ID cannot help you, ever. You need to do completely different thing. You don't need to do anything with the form. Form merely sends HTTP request. You should send exact same form of HTTP request. The problem cannot be solved for all possible forms. You should look at a particular form and see what it does. Don't try to feel in the form.
Send HTTP request.
—SA
Zack McIntosh at 11-Feb-13 18:02pm
   
I appreciate you taking the time to help me on this. I still have quite figured out the entire thing but I did make a web browser that puts the webrequest in and as for where the line is it has this div
 
[spoiler]
<div>
<input name="commit" type="submit" value="Login" /> or
 
Create Account ·
Forgot Password?
</div>[/spoiler]
 
Here is some more of it:
 
<div class="bh_padding">
Sign in
</div>
</div>
</div>
<div class='content'>
<div class='left_image'></div>
<div class='right_image'></div>
<div class='mid_image'><div></div></div>
<div class='inner_content'>
<div class="bc_padding">

<div class='message'>
 

<form accept-charset="UTF-8" action="/users/sign_in" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="iXZDAVAwPT35r4UVxKFTuodeZcMzvoyzwPpx+I17K24=" /></div>
<input id="return_to" name="return_to" type="hidden" />
 

<div>
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" size="30" type="text" value="" />
</div>
<div>
<label for="user_password">Password</label>
<input id="user_password" name="user[password]" size="30" type="password" />
</div>
<div>
<input name="user[remember_me]" type="hidden" value="0" /><input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1" /> <label class="checkbox" for="user_remember_me">Remember</label>
</div>
<div>
<input name="commit" type="submit" value="Login" /> or
 
Create Account ·
Forgot Password?
</div>
<div>

</div>
</form> </div>
 
</div>
</div>
</div>
<div class='footer'>
<div class='left_image'></div>
<div class='right_image'></div>
<div class='mid_image'><div></div></div>
<div class='inner_content'>
<div class="bf_padding">

</div>
</div>
</div>
</div>
 
</div>
 
</div>
</div>
 

</div>
</div>
</body>
</html>
 

Zack McIntosh at 11-Feb-13 13:09pm
   
Can I loop through all of the elements on the page until I get to the element with the value of the button and when it reaches that one have it click it?
Sergey Alexandrovich Kryukov at 11-Feb-13 14:43pm
   
Wrong idea. You can do it, but the solution is totally different. Please see my answer after [EDIT].
—SA
Maciej Los at 11-Feb-13 16:30pm
   
Short and to the point, +5!
I like to read your answers and comments ;)
Sergey Alexandrovich Kryukov at 11-Feb-13 16:46pm
   
Thank you very much, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid