用Watin登录网页 [英] Login in a Webpage with Watin
问题描述
我尝试在网页上登录。
在网页上有两种形式的输入,输入具有相同的Id(用户名)。
如何获得正确的输入来设置我的文本?
这是我的错代码:
browser.TextField(Find.ByName(username)) ).TypeText(test123);
或
browser.Form(Find.ByName(form_login ))。TextField(Find.ByName(username))。TypeText(test123);
收集页面中的所有文本字段,然后在所需ID的第一次或第二次出现时执行操作。
例如:
TextFieldCollection textFields = browser.TextFields;
foreach(textFields中的var字段)
{
if(field.Id ==username)
{
//做某事
}
}
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");
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
}
}
这篇关于用Watin登录网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!