public Rectangle GetElementRectangle(WebElementProperties webElementProperties) { Point pos = new Point(); pos.X = 0; pos.Y = 0; Size size = new Size(); try { pos = webElementProperties.WebElement.Location; size = webElementProperties.WebElement.Size; if (webElementProperties.IsInFrame) { _webDriver.SwitchTo().DefaultContent(); pos.Offset(webElementProperties.FrameElement.Location); //_webDriver.SwitchTo().Frame(webElementProperties.FrameElement); } } catch (OpenQA.Selenium.StaleElementReferenceException exception) { //the element is not available if (!_webDriver.Url.Equals(webElementProperties.BrowserURL)) { this.SwithToURL(webElementProperties.BrowserURL); } if (webElementProperties.IsInFrame) { //switch to frame _webDriver.SwitchTo().DefaultContent(); pos = webElementProperties.FrameElement.Location; _webDriver.SwitchTo().Frame(webElementProperties.FrameElement); } pos.Offset(webElementProperties.WebElement.Location); size = webElementProperties.WebElement.Size; } pos.X += (int)_toobarAutoElement.Current.BoundingRectangle.X; pos.Y += ((int)_toobarAutoElement.Current.BoundingRectangle.Y + (int)_toobarAutoElement.Current.BoundingRectangle.Height); return(new Rectangle(pos, size)); }
public static WebElementProperties createWebElementPropertiesWithWebElement(RemoteWebElement webElement, RemoteWebElement FrameElement, WebDriverHost webDriverHost) { if (webElement == null) { return(null); } //get web element's type string webCtrlType = WebKit.generateWebElementType(webElement); if (string.IsNullOrEmpty(webCtrlType)) { return(null); } WebElementProperties webEleProperties = new WebElementProperties(); webEleProperties._webElement = webElement; webEleProperties.BuildPropertiesWithControlType(webCtrlType); webEleProperties._isInFrame = FrameElement != null?true:false; webEleProperties.FrameElement = FrameElement; webEleProperties.BrowserURL = webElement.WrappedDriver.Url; webEleProperties._webDriverHost = webDriverHost; return(webEleProperties); }
public WebElementPropertiesList GenerateElementPropertiesLineByPoint(Point point) { _isInFrame = false; _webDriver.SwitchTo().DefaultContent(); point.X -= (int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.X; point.Y -= ((int)_toobarAutoElement.Current.BoundingRectangle.TopLeft.Y + (int)_toobarAutoElement.Current.BoundingRectangle.Height); _webSelectElement = WebUtility.FindElementByPoint(_webDriver, point); WebElementsList webElementsLine = null; WebElementPropertiesList webElementPropertiesList = null; //testing #if false RemoteWebElement frame = _webSelectElement; ReadOnlyCollection <IWebElement> res = _webDriver.FindElementsByTagName("frame"); ReadOnlyCollection <IWebElement> inputs = null; _webDriver.SwitchTo().Frame(res[1]); inputs = _webDriver.FindElementsByTagName("input"); _webDriver.SwitchTo().DefaultContent(); _webDriver.SwitchTo().Frame(res[1]); #endif #if false RemoteWebElement inputElement = _webDriver.FindElementByTagName("input") as RemoteWebElement; string currWindow = _webDriver.CurrentWindowHandle; RemoteWebDriver currWebDriver2 = null; foreach (string window in _webDriver.WindowHandles) { if (window.Equals(currWindow)) { continue; } currWebDriver2 = _webDriver.SwitchTo().Window(window) as RemoteWebDriver; break; } RemoteWebElement inputElement2 = _webDriver.FindElementByTagName("button") as RemoteWebElement; _webDriver.SwitchTo().Window(currWindow); Thread.Sleep(0); #endif //testing end if (_webSelectElement.TagName.ToUpper().IndexOf("FRAME") >= 0) { //Currently, window handle is pointing to main page webElementsLine = GenerateWebElementsLine(_webSelectElement); //Generate the WebElementProperties list - since the window handle will be switched to iFrame //the Selenium elements will be not available //Currently, the generated elements are in the main page, can't get the elements in the iFrame page webElementPropertiesList = webElementsLine .Select(element => { return(WebElementProperties.createWebElementPropertiesWithWebElement(element, null, this)); }) .Where(resElementProperties => resElementProperties != null).ToList(); point.X -= _webSelectElement.Location.X; point.Y -= _webSelectElement.Location.Y; //Currently, window handle is pointing to iFrame page, can get the elements in the iFrame page _webDriver.SwitchTo().Frame(_webSelectElement); RemoteWebElement FrameElement = _webSelectElement; _webSelectElement = WebUtility.FindElementByPoint(_webDriver, point); webElementsLine = GenerateWebElementsLine(_webSelectElement); //don't need the WebPage since the WebFrame object has been already inserted into the list, it is the "WebPage" for the iFrame page webElementPropertiesList.AddRange(webElementsLine .Select(element => { return(WebElementProperties.createWebElementPropertiesWithWebElement(element, FrameElement, this)); }) .Where(resElementProperties => resElementProperties != null && !resElementProperties.ControlTypeString.Equals("WebPage")).ToList()); } else { webElementPropertiesList = GenerateWebElementsLine(_webSelectElement) .Select(element => { return(WebElementProperties.createWebElementPropertiesWithWebElement(element, null, this)); }) .Where(resElementProperties => resElementProperties != null).ToList(); } return(webElementPropertiesList); }