How to fill a specific input field with WatiN, when multiple inputs have the same “Name”?

陌路散爱 提交于 2019-12-02 02:10:49

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/8175699/how-to-fill-a-specific-input-field-with-watin-when-multiple-inputs-have-the-sam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!