tags:

views:

37

answers:

1

this is the form

<form action="j_security_check" method="post">
<div id="editForm">

<h2>Login</h2>

<div class="errors"></div>

<div class="row">
    <span class="label">Username:</span>
    <span class="formw"><input type="text" name="j_username"></span>
</div>

<div class="row">
    <span class="label">Password:</span>
    <span class="formw"><input type="password" name="j_password"></span>

</div>

<div class="submit">
    <input type="submit" value="Login">
</div>
</div>

</form></body>

the Button dosent have a name so im stomped in how to get this to work? the button doens have a ID or name so i cant use the GetElementById or GetElementsByName

webBrowser1.Document.All.GetElementsByName("j_username")[0].SetAttribute("Value", "************");
        webBrowser1.Document.All.GetElementsByName("j_password")[0].SetAttribute("Value", "******");
        webBrowser1.Document.All["Login"].InvokeMember("click");

;

anyone have a suggestion?

+2  A: 

You could use GetElementsByTagName

    HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("INPUT");
    foreach (HtmlElement elem in elems)
    {
        String valueStr = elem.GetAttribute("value");
        if (valueStr != null && valueStr.Equals("Login"))
        {
            elem.InvokeMember("click");                
        }
    }

I know that there are shorter ways to do this using LINQ however I think this is the clearest example of what is going on.

James J. Regan IV
thx mate i will check this at work tomorrow.
Darkmage
ty mate got this working fine.,,, but you got one typo, edit the nameStr to valueStr in your post.
Darkmage
Ahh thanks, I took this from the example for `GetAttribute` from the MSDN, I just have missed that one.
James J. Regan IV