How to fill a specific input field with WatiN, when multiple inputs have the same quot;Namequot;?(当多个输入具有相同的“名称时,如何使用 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 填充特定输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当多个输入具有相同的“名称"时,如何使用


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01