How to fill a specific input field with WatiN, whe

2020-04-10 02:34发布

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条回答
甜甜的少女心
2楼-- · 2020-04-10 03:03

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";
查看更多
登录 后发表回答