问题描述
我正在使用 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 填充特定输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!