用Watin登录网页 [英] Login in a Webpage with Watin

查看:213
本文介绍了用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆