Esempio n. 1
0
        public static string RunControl(List <HControl> controls, string data, IE ie)
        {
            int    i      = 0;
            string status = "Error";

            while (i < Loop)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.AHrefNoText:
                    {
                        ie.GoTo(control.Value);
                        ie.WaitForComplete();
                        return(String.Empty);

                        break;
                    }

                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Div:
                    {
                        WatiN.Core.Div obj = MyWatiN.GetDiv(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(ie, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(ie, control);
                        if (obj != null)
                        {
                            obj.Checked = bool.Parse(data);
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }
                    }
                }
                Thread.Sleep(1000);
            }
            return(status);
        }
Esempio n. 2
0
        public static bool CheckExist(List <HControl> controls, IE ie)
        {
            int  i      = 0;
            bool status = false;

            while (i < 2)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.AHref:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Div:
                    {
                        WatiN.Core.Div obj = MyWatiN.GetDiv(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(ie, control);
                        if (obj != null)
                        {
                            return(true);
                        }
                        break;
                    }
                    }
                }
                if (i < 1)
                {
                    Thread.Sleep(1000);
                }
            }
            return(status);
        }
Esempio n. 3
0
        public static string RunControl(List <HControl> controls, string data, Div div, IE ie)
        {
            int    i      = 0;
            string status = "Error";

            while (i < Loop)
            {
                i++;
                foreach (HControl control in controls)
                {
                    switch (control.Control.ToLower())
                    {
                    case ControlType.Link:
                    {
                        WatiN.Core.Link obj = MyWatiN.GetLink(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Button:
                    {
                        WatiN.Core.Button obj = MyWatiN.GetButton(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.Image:
                    {
                        WatiN.Core.Image obj = MyWatiN.GetImage(div, control);
                        if (obj != null)
                        {
                            obj.Click();
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextArea:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(div, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.TextBox:
                    {
                        WatiN.Core.TextField obj = MyWatiN.GetTextField(div, control);
                        if (obj != null)
                        {
                            obj.Value = data;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }

                    case ControlType.CheckBox:
                    {
                        WatiN.Core.CheckBox obj = MyWatiN.GetCheckBox(div, control);
                        if (obj != null)
                        {
                            obj.Checked = true;
                            ie.WaitForComplete();
                            return(String.Empty);
                        }
                        break;
                    }
                    }
                }
                if (i < Loop - 1)
                {
                    Thread.Sleep(1000);
                }
            }
            return(status);
        }
Esempio n. 4
0
        private WatinControl CreateWatinControl(INativeElement htmlElem)
        {
            Element          watElem;
            WatinBaseControl watBaseTypeElem;
            int    watElemIndex = 0;
            int    sourceIdx    = htmlElem.GetElementSourceIndex();
            string getByTag     = htmlElem.TagName;

            switch (getByTag)
            {
            case "AREA":
                watElem         = new Area(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Areas);
                IEnumerator <Area> areaEnum = docElement.Areas.GetEnumerator();

                while (areaEnum.MoveNext())
                {
                    if (areaEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "INPUT":
                string byType = htmlElem.GetAttributeValue("type");
                switch (byType)
                {
                case "submit":
                case "reset":
                case "button":
                    watElem         = new WatiN.Core.Button(docElement.DomContainer, htmlElem);
                    watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Buttons);
                    IEnumerator <WatiN.Core.Button> buttonEnum = docElement.Buttons.GetEnumerator();

                    while (buttonEnum.MoveNext())
                    {
                        if (buttonEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                        {
                            break;
                        }
                        watElemIndex++;
                    }
                    return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

                case "checkbox":
                    watElem         = new WatiN.Core.CheckBox(docElement.DomContainer, htmlElem);
                    watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.CheckBoxes);
                    IEnumerator <WatiN.Core.CheckBox> cbEnum = docElement.CheckBoxes.GetEnumerator();

                    while (cbEnum.MoveNext())
                    {
                        if (cbEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                        {
                            break;
                        }
                        watElemIndex++;
                    }
                    return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

                case "file":
                    watElem         = new FileUpload(docElement.DomContainer, htmlElem);
                    watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.FileUploads);
                    IEnumerator <FileUpload> fuEnum = docElement.FileUploads.GetEnumerator();

                    while (fuEnum.MoveNext())
                    {
                        if (fuEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                        {
                            break;
                        }
                        watElemIndex++;
                    }
                    return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

                case "hidden":
                case "password":
                case "text":
                case "textarea":
                    watElem         = new TextField(docElement.DomContainer, htmlElem);
                    watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.TextFields);
                    IEnumerator <TextField> tfEnum = docElement.TextFields.GetEnumerator();

                    while (tfEnum.MoveNext())
                    {
                        if (tfEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                        {
                            break;
                        }
                        watElemIndex++;
                    }
                    return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

                case "radio":
                    watElem         = new WatiN.Core.RadioButton(docElement.DomContainer, htmlElem);
                    watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.RadioButtons);
                    IEnumerator <WatiN.Core.RadioButton> rbEnum = docElement.RadioButtons.GetEnumerator();

                    while (rbEnum.MoveNext())
                    {
                        if (rbEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                        {
                            break;
                        }
                        watElemIndex++;
                    }
                    return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));
                }
                break;

            case "DIV":
                watElem         = new Div(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Divs);
                IEnumerator <Div> divEnum = docElement.Divs.GetEnumerator();

                while (divEnum.MoveNext())
                {
                    if (divEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "FORM":
                watElem         = new WatiN.Core.Form(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Forms);
                IEnumerator <WatiN.Core.Form> formEnum = docElement.Forms.GetEnumerator();

                while (formEnum.MoveNext())
                {
                    if (formEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "FRAME":
            case "IFRAME":
                //watFrame = new Frame(browser.DomContainer, htmlElem);
                //watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Forms);
                //IEnumerator<Form> formEnum = browser.Forms.GetEnumerator();

                //while (formEnum.MoveNext())
                //{
                //	  if (formEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                //		  break;
                //	  watElemIndex++;
                //}
                //return new WatinControl(watBaseTypeElem, watElem, watElemIndex);
                break;

            case "IMG":
                watElem         = new Image(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Images);
                IEnumerator <Image> imgEnum = docElement.Images.GetEnumerator();

                while (imgEnum.MoveNext())
                {
                    if (imgEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "LABLE":
                watElem         = new WatiN.Core.Label(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Labels);
                IEnumerator <WatiN.Core.Label> lblEnum = docElement.Labels.GetEnumerator();

                while (lblEnum.MoveNext())
                {
                    if (lblEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "A":
                watElem         = new Link(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Links);
                IEnumerator <Link> lnkEnum = docElement.Links.GetEnumerator();

                while (lnkEnum.MoveNext())
                {
                    if (lnkEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "P":
                watElem         = new Para(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Paras);
                IEnumerator <Para> paraEnum = docElement.Paras.GetEnumerator();

                while (paraEnum.MoveNext())
                {
                    if (paraEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "SELECT":
                watElem         = new SelectList(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.SelectLists);
                IEnumerator <SelectList> slEnum = docElement.SelectLists.GetEnumerator();

                while (slEnum.MoveNext())
                {
                    if (slEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "SPAN":
                watElem         = new Span(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Spans);
                IEnumerator <Span> spanEnum = docElement.Spans.GetEnumerator();

                while (spanEnum.MoveNext())
                {
                    if (spanEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "TBODY":
                watElem         = new TableBody(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.TableBodies);
                IEnumerator <TableBody> tbEnum = docElement.TableBodies.GetEnumerator();

                while (tbEnum.MoveNext())
                {
                    if (tbEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "TD":
                watElem         = new TableCell(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.TableCells);
                IEnumerator <TableCell> tdEnum = docElement.TableCells.GetEnumerator();

                while (tdEnum.MoveNext())
                {
                    if (tdEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "TR":
                watElem         = new TableRow(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.TableRows);
                IEnumerator <TableRow> trEnum = docElement.TableRows.GetEnumerator();

                while (trEnum.MoveNext())
                {
                    if (trEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "TABLE":
                watElem         = new Table(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Tables);
                IEnumerator <Table> tableEnum = docElement.Tables.GetEnumerator();

                while (tableEnum.MoveNext())
                {
                    if (tableEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            case "TEXTAREA":
                watElem         = new TextField(docElement.DomContainer, htmlElem);
                watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.TextFields);
                IEnumerator <TextField> taEnum = docElement.TextFields.GetEnumerator();

                while (taEnum.MoveNext())
                {
                    if (taEnum.Current.NativeElement.GetElementSourceIndex() == sourceIdx)
                    {
                        break;
                    }
                    watElemIndex++;
                }
                return(new WatinControl(watBaseTypeElem, watElem, watElemIndex));

            default:
                return(null);
            }

            return(null);
        }