public WebElementsList GenerateWebElementsLine(RemoteWebElement webElement) { WebElementsList webElementsLine = WebUtility.GenerateWebElementsLine(webElement); //if the element is in a frame, need to switch to the top /*if (_isInFrame) * { * _webDriver.SwitchTo().DefaultContent(); * // _currFrameElement. * * }*/ return(webElementsLine); }
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); }