Beispiel #1
0
        /// <summary>
        /// Retrieve the html eleme from document by x,y position in the doc.
        /// Create a Watin Element and by finding the control type and index create the WatingControl.
        /// </summary>
        /// <param name="x">X positing of the control relative to the document (body, upper left it 0,0)</param>
        /// <param name="y">Y positing of the control relative to the document (body, upper left it 0,0)</param>
        /// <returns>Watin control with known groupe type and index inside the group</returns>
        public WatinControl GetElementFromPoint(int x, int y)
        {
            WatinControl wat;
            //  Point er = new Point(x,y);
            //Thread th = new System.Threading.Thread(new ParameterizedThreadStart(ControlFromPointWorker));
            // th.Start(er);
            // th.Join();

            INativeElement htmlElem = browser.NativeDocument.ElementFromPoint(x, y);

            if (htmlElem.TagName.Contains("FRAME"))
            {
                int sourceIdx = htmlElem.GetElementSourceIndex();
                WatinBaseControl watBaseTypeElem = new WatinBaseControl(this, WatinBaseTypes.Frames);

                IEnumerator <Frame> frmEnum = browser.Frames.GetEnumerator();

                while (frmEnum.MoveNext())
                {
                    INativeElement htmlElem2 = frmEnum.Current.NativeDocument.ContainingFrameElement;
                    if (sourceIdx == htmlElem2.GetElementSourceIndex())
                    {
                        WatFrame frameParent = new WatFrame(new WatinBaseControl(this, WatinBaseTypes.Frames), frmEnum.Current, sourceIdx);

                        //htmlElem = frmEnum.Current.NativeDocument.ElementFromPoint(x - htmlElem2.GetAbsElementBounds().Left, y - htmlElem2.GetAbsElementBounds().Top);
                        //wat = CreateWatinControl(htmlElem);
                        return(frameParent.GetControlFromPoint(x, y));
                    }
                }
            }

            wat = CreateWatinControl(htmlElem);
            return(wat);
        }
Beispiel #2
0
 public WatinControl(WatinBaseControl parent, WatiN.Core.Element element, int idx)
 {
     _parent = parent;
     if (element != null)
     {
         htmlElement = element;
         _index      = idx;
     }
 }
Beispiel #3
0
 public WatFrame(WatinBaseControl parent, WatiN.Core.Frame element, int idx)
 {
     _parent = parent;
     if (element != null)
     {
         docElement = element;
         // docElement
         _index = idx;
     }
 }
Beispiel #4
0
        public override UIControlBase[] GetChildren()
        {
            WatinBaseControl parent = ((WatinBaseControl )Parent);

            if (parent.BaseType == WatinBaseTypes.Tables)
            {
                return new UIControlBase[] { new WatinBaseControl(this, WatinBaseTypes.Tables) }
            }
            ;

            if (parent.BaseType == WatinBaseTypes.TableRows)
            {
                return new UIControlBase[] { new WatinBaseControl(this, WatinBaseTypes.TableCells) }
            }
            ;

            return(base.GetChildren());
        }
Beispiel #5
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);
        }