0

Ho do I select the first item in a SelectList in WatiN? Below you can see how I have my selectlist declared and below that is how I'm attempting to call the select. I don't see any options for index. Will I need to get a string collection of selected items and select by the [1] string or is there a simpler way to do this?

Page Class:

[FindBy(Id = "VariationRelationshipId")]
public SelectList VariationRelationship { get; set; }

Test Class:

//need to select 1st item in list
Browser.Page<MyPage>().VariationRelationship........
4

1 回答 1

3

您需要针对浏览器的实例而不是Watin.Core.Browser类调用

测试代码。

IE myBrowser = new IE(true);
myBrowser.GoTo("http://www.tizag.com/htmlT/htmlselect.php");           
myBrowser.Page<DropDownSample>().States.WaitUntilExists();
myBrowser.Page<DropDownSample>().States.Options[2].Select();  //<-- not Browser.Page....

班级

public class DropDownSample : Page
    {
        [FindBy(Name = "selectionField")]
        public SelectList States { get; set; }
    }

上面在 Watin2.1、IE9、Win7 上进行了检查 - 运行得像个冠军。在页面上的第一个选择列表中选择“conneticut”。

于 2012-11-19T21:39:41.047 回答