views:

87

answers:

1

I try to login on a webpage. On the webpage are two forms with inputs, the inputs have the same Id("username").

How can i get the right inputs to set my text?

This is my wrong Code:

browser.TextField(Find.ByName("username")).TypeText("test123");

or

browser.Form(Find.ByName("form_login")).TextField(Find.ByName("username")).TypeText("test123");

A: 

You can collect all text field in the page and then perform the action on the first or second appearance of the desired id.

For example:

        TextFieldCollection textFields = browser.TextFields;
        foreach (var field in textFields)
        {
            if (field.Id == "username")
            { 
                //do something
            }
        }
alonp