Exemplo n.º 1
0
 public static void SetCheckBox(HpgElement box, bool check)
 {
     if (box.Element.Selected != check) //Only perform action if the box is currently different
     {
         if (check)
         {
             box.Check();
         }
         else
         {
             box.UnCheck();
         }
     }
 }
Exemplo n.º 2
0
        public string FillFormField(HpgElement field, string fieldValue)
        {
            //HpgAssert.Exists(field, "Verify field '" + field.Element.Id + "' exists");
            string originalValue = "";
            string elementType   = field.Element["outerHTML"];

            elementType = elementType.Substring(1, elementType.IndexOf(' ')).Trim().ToLower();
            switch (elementType)
            {
            case "input":
                //Text, Check, or Radio
                switch (field.Element["type"].ToLower())
                {
                case "text":
                    //text box
                    originalValue = field.Text;
                    field.Type(fieldValue);
                    break;

                case "checkbox":
                    //check box
                    if (field.Element.Selected)
                    {
                        originalValue = "TRUE";
                    }
                    if (fieldValue.Trim().Equals(""))
                    {
                        field.Element.Click();
                        field.UnCheck();
                    }
                    else
                    {
                        field.Element.Click();
                        field.Check();
                    }
                    break;

                case "radio":
                    //radio button
                    ElementScope originalSelection = browser.FindXPath("//input[@name='" + field.Element.Id + "' and @checked='true']");
                    if (originalSelection.Exists())
                    {
                        originalValue = originalSelection.Value;
                    }
                    field.Element.Click();
                    browser.Choose(field.Element.Id);
                    break;
                }
                break;

            case "select":
                //Drop-Down
                originalValue = field.Element.SelectedOption;
                field.Click();
                field.Element.SendKeys(fieldValue);
                field.Element.FindXPath(".//*[.='" + fieldValue + "']").Click();
                browser.Select(fieldValue).From(field.Element.Id);
                break;

            case "textarea":
                //Large text area
                originalValue = field.Text;
                field.Type(fieldValue);
                break;
            }
            return(originalValue);
        }