internal void LaunchWebDriverHost() { if (_webDriverHost != null) { _webDriverHost.Dispose(); } _webDriverHost = new WebDriverHost(); }
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 ConstructElementsTree(RemoteWebElement webElement) { this.objectTree.Nodes.Clear(); if (webElement == null) { return; } // UIAHighlight.HighlightThread_Spy(clickedElement); // List<AutomationElement> elements = UIAUtility.GetAutomationElementsLine(clickedElement); WebDriverHost webBrowerWrapper = this.Tag as WebDriverHost; List <RemoteWebElement> webElements = webBrowerWrapper.GenerateWebElementsLine(webElement); TreeNodesFromAutomationElements(webElements); // if (_modeType == AddObjWndModeType.Normal) // ConstructLeftAndRightNode(objectTree, clickedElement); this.objectTree.ExpandAll(); }
private void HighlightObjectThread(object param) { try { TestObjectNurse nurseObject = param as TestObjectNurse; if (nurseObject == null) { return; } ITestObject testObject = nurseObject.TestObject; SetStatusText(StringResources.LPSpy_SpyMainWindow_Identifying); //Check whether the WebDriver Host exist or not if (testObject.ControlTypeString.StartsWith("Web")) { SETestObject seTestObject = testObject as SETestObject; if (seTestObject.SEWebElement == null) { //look for WebPage TreeNode parentNode = nurseObject.TreeNode; ITestObject parentObject = null; do { parentObject = TestObjectNurse.FromTreeNode(parentNode).TestObject; if (parentObject.ControlTypeString.Equals("WebPage")) { //seTestObject = parentObject as SETestObject; break; } }while (null != (parentNode = parentNode.Parent)); if (null != parentObject) { //check the WebDriverHost existing if (null == _webDriverHost) { _webDriverHost = new WebDriverHost(); _webDriverHost.GotoUrl(parentObject.Properties[WebControlKeys.URL]); } else { _webDriverHost.SwithToURL(parentObject.Properties[WebControlKeys.URL]); } WebRefreshNodeTag(parentNode); } } Rectangle rc = _webDriverHost.GetElementRectangle(seTestObject); UIAHighlight.HighlightRect(rc); return; } if (!UIAHighlight.SearchAndHighlight(testObject)) { MessageBox.Show(StringResources.LPSpy_SpyMainWindow_CannotFindObjectMsg); } } finally { SetStatusText(""); } }
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); } }