private void TreeNodesFromAutomationElements(List <RemoteWebElement> webElements)
        {
            TreeNodeCollection currentNodes = this.objectTree.Nodes;
            TreeNode           tempNode     = null;

            int index = 0;

            foreach (RemoteWebElement webelement in webElements)
            {
                WebElementProperties webElementProperties = new WebElementProperties(webelement);
                if (string.IsNullOrEmpty(webElementProperties.ControlTypeString))
                {
                    continue;
                }
                tempNode     = currentNodes.Add(index.ToString(), webElementProperties.Name);
                tempNode.Tag = webElementProperties;
                TreeNodeHelper.FixTreeNodeImage(tempNode, "Button");
                currentNodes     = tempNode.Nodes;
                tempNode.Checked = true;
            }

            TreeNode currentNode = tempNode;

            currentNode.Name        = "self";
            currentNode.Checked     = true;
            objectTree.SelectedNode = currentNode;

            // _selfElement = (ElementProperties)currentNode.Tag;
        }
        private bool PreGetNurseObjectsLine(IElementProperties elementProperties)
        {
            WebElementProperties webElementProperties = elementProperties as WebElementProperties;

            if (null == webElementProperties)
            {
                return(false);
            }

            string        ctrlType      = webElementProperties.ControlTypeString;
            WebDriverHost webDriverHost = this.Tag as WebDriverHost;

            //WebPage & WebFrame must be inserted into the elements line since the Web driver should be switched to relevant window when
            //using it to get properties of some web element
            //and in order to find such window, the URL and src property which is included in webPage & WebFrame should be used.
            switch (ctrlType)
            {
            case "WebPage":
            {
                //in order to add Webpage object, need to switch to its window.
                webDriverHost.SwitchRelevantWindow(webElementProperties.Properties[WebControlKeys.URL]);
                return(true);
            }

            case "WebFrame":
            {
                webDriverHost.SwitchRelevantWindow(webElementProperties.WebElement);
                return(true);
            }

            default:
            {
                if (!ctrlType.StartsWith("Web"))
                {
                    return(true);
                }
            }
            break;
            }
            return(false);
        }
        private void PointToSpiedData(Point mousePoint)
        {
            try
            {
                AutomationElement clickedElement = AutomationElement.FromPoint(mousePoint);

                WebDriverHost webDriverHost = this.Tag as WebDriverHost;
                if (null != webDriverHost && clickedElement.Current.ClassName.Equals("Chrome_RenderWidgetHostHWND"))
                {
                    System.Drawing.Point point = new System.Drawing.Point((int)mousePoint.X, (int)mousePoint.Y);
                    webDriverHost.CheckWindowHandle(clickedElement);

                    // RemoteWebElement webElement = webDriverHost.FindElementByPoint(point) as RemoteWebElement;

                    /* if (SpySettings.CaptureSnapshots && null != webElement)
                     * {
                     *   //capture snapshot of clicked area
                     *   SnapshotHelper.CaptureTempSnapshot(webElement, out _token);
                     * }*/
                    //  WebUtility.GetElementScreenRect(webElement);
                    // UIAHighlight.HighlightRect( WebUtility.GetElementScreenRect(webElement));
                    //     webDriverHost.HighlightWebElement(webElement);
                    //     ConstructElementsTree(webElement);

                    /* List<RemoteWebElement> webElements = webDriverHost.GenerateElementsLineByPoint(point);
                     *
                     * TreeNodesFromAutomationElements(webElements);*/
                    System.Drawing.Rectangle    rect = System.Drawing.Rectangle.Empty;
                    List <WebElementProperties> webElementProperiesList = webDriverHost.GenerateElementPropertiesLineByPoint(point);
                    if (webElementProperiesList.Count > 0)
                    {
                        WebElementProperties webElementProperties = webElementProperiesList[webElementProperiesList.Count - 1];
                        rect = webDriverHost.GetElementRectangle(webElementProperties);
                        UIAHighlight.HighlightRect(rect);
                    }
                    TreeNodesFromWebElementProperties(webDriverHost.GenerateElementPropertiesLineByPoint(point));
                    //webDriverHost.GetElementRectangle()
                    // UIAHighlight.HighlightRect(WebUtility.GetElementScreenRect(webDriverHost.WebSelectElement));
                    if (SpySettings.CaptureSnapshots && !rect.IsEmpty)
                    {
                        //capture snapshot of clicked area

                        SnapshotHelper.CaptureTempSnapshot(rect, out _token);
                    }


                    this.objectTree.ExpandAll();
                    return;
                }



                ConstructElementsTree(clickedElement);

                _token = null;

                if (SpySettings.CaptureSnapshots)
                {
                    //capture snapshot of clicked area
                    SnapshotHelper.CaptureTempSnapshot(clickedElement, out _token);
                }
            }
            catch (ElementNotAvailableException)
            {
                //Element is no longer available, please reselect the element
                MessageBox.Show(StringResources.LPSpy_ElementNotAvailableException);
            }
        }