当多个输入具有相同的“名称"时,如何用WatiN填充特定的输入字段? [英] How to fill a specific input field with WatiN, when multiple inputs have the same "Name"?

查看:123
本文介绍了当多个输入具有相同的“名称"时,如何用WatiN填充特定的输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WatiN和C#在线填写表单,但是我的搜索"字段与另一个元素具有相同的名称.我的搜索字段定义如下:

I'm using WatiN and C# to fill out a form online but my Search field has the same name as another element. My search field is defined as follows:

<input type="text" value="" size="50" name="search">

在同一屏幕的另一部分中,还有一个不同的搜索字段,定义为:

There is also a different search field in another section of the same screen defined as:

<input class="Search-TextBox" type="text" value="" size="15" name="search">

我想填写前面提到的文本输入搜索字段.有没有可能根据尺寸找到并填充搜索框的方法?

I want to fill out the formerly mentioned text input search field. Is there a way to find and fill the search box based on size maybe?

我对搜索字段的提交"按钮有相​​同的问题.它的名称和大小相同,因此如何指定要单击搜索的按钮?

I have the same issue with the search field's Submit button. Its the same name and size so how do I specify which button to click search on?

推荐答案

您可以使用以下任何一种机制

You can use any of the following mechanisms

browserinstance.TextField(t => t.Name == "search" && t.GetAttributeValue("size") == "50").Value = "value";
//OR
browserinstance.TextField(Find.ByName("search").And(Find.By("size","50"))).Value = "value";

如果所有属性都相同,则可以在获得过滤列表后根据顺序进行搜索.

If all the attributes are the same, you can search on the basis of the ordering after getting a filtered list.

browserinstance.TextFields.Filter(Find.ByName("search"))[0].Value = "value";

这篇关于当多个输入具有相同的“名称"时,如何用WatiN填充特定的输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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