public static SizeAndBorders GetSizeAndBorders(IWebElement element, IJavaScriptExecutor jsExecutor, Logger logger = null) { SizeAndBorders retval = new SizeAndBorders(); try { if (jsExecutor.ExecuteScript(JS_GET_SIZE_AND_BORDER_WIDTHS, element) is string sizeAndBordersStr) { sizeAndBordersStr = sizeAndBordersStr.Replace("px", ""); string[] data = sizeAndBordersStr.Split(','); retval.Size = new Size( (int)Math.Ceiling(Convert.ToSingle(data[0], NumberFormatInfo.InvariantInfo)), (int)Math.Ceiling(Convert.ToSingle(data[1], NumberFormatInfo.InvariantInfo)) ); retval.Borders = new RectangularMargins( (int)Math.Ceiling(Convert.ToSingle(data[2], NumberFormatInfo.InvariantInfo)), (int)Math.Ceiling(Convert.ToSingle(data[3], NumberFormatInfo.InvariantInfo)), (int)Math.Ceiling(Convert.ToSingle(data[4], NumberFormatInfo.InvariantInfo)), (int)Math.Ceiling(Convert.ToSingle(data[5], NumberFormatInfo.InvariantInfo)) ); } } catch { retval.Size = GetClientSize(element, jsExecutor, logger); retval.Borders = GetBorderWidths(element, jsExecutor, logger); } return(retval); }
private void WillSwitchToFrame_(IWebElement targetFrame) { ArgumentGuard.NotNull(targetFrame, nameof(targetFrame)); if (!(targetFrame is EyesRemoteWebElement eyesFrame)) { eyesFrame = new EyesRemoteWebElement(logger_, driver_, targetFrame); } Point pl = targetFrame.Location; Size ds = targetFrame.Size; SizeAndBorders sizeAndBorders = eyesFrame.SizeAndBorders; RectangularMargins borderWidths = sizeAndBorders.Borders; Size clientSize = sizeAndBorders.Size; Rectangle bounds = eyesFrame.GetClientBounds(); Point contentLocation = new Point(bounds.X + borderWidths.Left, bounds.Y + borderWidths.Top); //Point originalLocation = ScrollPositionProvider.GetCurrentPosition(jsExecutor_, driver_.FindElement(By.TagName("html"))); Point originalLocation = eyesFrame.ScrollPosition; Frame frame = new Frame(logger_, targetFrame, contentLocation, new Size(ds.Width, ds.Height), clientSize, originalLocation, bounds, borderWidths, jsExecutor_); driver_.GetFrameChain().Push(frame); }
private Point CalcFrameLocationInScreenshot_(FrameChain frameChain, ScreenshotTypeEnum screenshotType) { EyesWebDriverTargetLocator switchTo = (EyesWebDriverTargetLocator)driver_.SwitchTo(); FrameChain currentFC = frameChain.Clone(); switchTo.DefaultContent(); Point locationInScreenshot = Point.Empty; foreach (Frame frame in currentFC) { Rectangle rect = ((EyesRemoteWebElement)frame.Reference).GetClientBounds(); SizeAndBorders sizeAndBorders = ((EyesRemoteWebElement)frame.Reference).SizeAndBorders; RectangularMargins borders = sizeAndBorders.Borders; rect.Offset(borders.Left, borders.Top); locationInScreenshot.Offset(rect.Location); switchTo.Frame(frame.Reference); } return(locationInScreenshot); }
private void WillSwitchToFrame_(IWebElement targetFrame) { ArgumentGuard.NotNull(targetFrame, nameof(targetFrame)); if (!(targetFrame is EyesRemoteWebElement eyesFrame)) { eyesFrame = new EyesRemoteWebElement(logger_, driver_, targetFrame); } Size ds = targetFrame.Size; SizeAndBorders sizeAndBorders = eyesFrame.SizeAndBorders; RectangularMargins borderWidths = sizeAndBorders.Borders; Size clientSize = sizeAndBorders.Size; Rectangle bounds = eyesFrame.GetClientBounds(); Point contentLocation = new Point(bounds.X + borderWidths.Left, bounds.Y + borderWidths.Top); Point originalLocation = eyesFrame.ScrollPosition; Frame frame = new Frame(logger_, targetFrame, contentLocation, new Size(ds.Width, ds.Height), clientSize, originalLocation, bounds, borderWidths, jsExecutor_); var activeElementBeforeSwitch = targetLocator_.ActiveElement(); targetLocator_.Frame(targetFrame); var activeElementAfterSwitch = targetLocator_.ActiveElement(); if (!activeElementAfterSwitch.Equals(activeElementBeforeSwitch)) { driver_.GetFrameChain().Push(frame); } else { throw new Exception("Failed switching to frame."); } }