当多个输入具有相同的“名称”时,如何用 WatiN 填充特定的输入字段?

发布于 2024-12-16 15:43:22 字数 396 浏览 1 评论 0原文

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

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

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

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

我想填写前面提到的文本输入搜索字段。有没有办法根据大小查找并填充搜索框?

我对搜索字段的“提交”按钮也有同样的问题。它的名称和大小相同,那么我如何指定单击哪个按钮进行搜索?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意 2024-12-23 15:43:22

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

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";

如果所有属性都相同,您可以在获得过滤列表后按顺序进行搜索。

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

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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文