Is there a way to iterate all form field in WatiN? Code snippet would be high开发者_JAVA技巧ly appreciated. Thanks.
string url = "http://localhost//test.htm";
string formId = "myFormId"; 
IE ie = new IE(url);
Form form = ie.Form(formId);            
CheckBoxCollection checkBoxCollection = form.CheckBoxes;
for (int index = 0, total = checkBoxCollection.Count; index < total; index++) {
    CheckBox checkBox = checkBoxCollection[index];
    this.AddInputControl(checkBox.Id, checkBox);
}
RadioButtonCollection radioButtonCollection = form.RadioButtons;
for (int index = 0, total = radioButtonCollection.Count; index < total; index++) {
    RadioButton radioButton = radioButtonCollection[index];
    this.AddInputControl(radioButton.Id, radioButton);
}
SelectListCollection selectListCollection = form.SelectLists;
for (int index = 0, total = selectListCollection.Count; index < total; index++) {
    SelectList selectList = selectListCollection[index];
    this.AddInputControl(selectList.Id, selectList);
}
TextFieldCollection textFieldCollection = form.TextFields;
for (int index = 0, total = textFieldCollection.Count; index < total; index++) {
    TextField textField = textFieldCollection[index];
    this.AddInputControl(textField.Id, textField);
}
Try this:
string url = "http://localhost//test.htm";
string formId = "myFormId"; 
IE ie = new IE(url);
Form form = ie.Form(formId); 
ElementCollection elements = form.Elements.Filter(Find.ByElement(x =>
{
  return x is TextField || x is SelectList || x is RadioButton || x is CheckBox;
}));
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论