Login in a Webpage with Watin

不羁的心 提交于 2019-12-11 00:25:54

问题


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");


回答1:


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
            }
        }


来源:https://stackoverflow.com/questions/2965524/login-in-a-webpage-with-watin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!