c# - WatiN NativeElement.GetElementBounds() - What is the unit of measurement? -


When I'm testing with WatiN, I have to save the screenshot. Sometimes I really do not need a picture of the entire browser window - though I want a picture of the element that I am testing.

My attempt to save the photo of an element with the code below, which resulted in a picture of a block box as shown, because the elementbind. The top point for a pixel position before the bottom of the screen Element Bounds. Farewell and. High value also seems to be about half that what they should be.

Is this a WatiN bug, or is there a different unit of these properties, which I have to convert in pixels in some way?

Public stable service scratches (WatiN.Core.IE, WatiN.Core.Element element, string screenshot path) {ScrollIntoView (i.e., element); Ie.BringToFront (); Var ieClass = (InternetExplorerClass) IE.InternetExplorer; Rectangle Element Bound = Element met. Element GetElementBounds (); Int left = ie class. Left + element bounce Left; Int top = ieClass.Top + elementBounds.Top; Int width = element bounds Wide; Intimate height = element bounds. Lightweight; (Using Graphics Graphics = Graphics FrameJames (bitmap)) (var bitmap = new bitmap (width, height)) {graphics.CopyFromScreen (new point (left, top), point blank, new size ( Width Height) ); } Bitmap.Save (screenshotPath, ImageFormat.Jpeg); }}

It seems that this is a WatiN bug as discussed The "boundivity" method for the Internet Explorer elements looks like this:

  Internal Rectangle Rectangle GetHtmlElementBounds (IHTMLElement element) {int offsetLeft = element.offsetLeft; Int offsetTop = element.offsetTop; (IHTMLElement element2 = element.parentElement; element2! = Zero; element2 = element2.parentElement) {offsetLeft + = element2.offsetLeft; OffsetTop + = element2.offsetTop; } Int width = element.offsetWidth / 2; Return a new rectangle (offset left, offsettop, width, element.offsetHyight / 2); }  

The bug is that it is dividing offsetwid and offset from Hight 2.

I have changed the call to element.ActiveElement.GetElementBounds to call my own "GetElementBounds" method, and the way I want it works:

  Private Rectangle Rectangle Gate element element (element element) {var ieElem = element.NativeElement as WatiN.Core.Native.InternetExplorer.IEElement; IHTMLElement elem = Meaning Elem.AsHtmlElement; Int left = elem.offsetLeft; Int top = elem.offsetTop; (IHTMLElement parent = elem.offsetParent; parent! = Null; parent = parent.offsetParent) {left + = parent.offsetLeft; Top + = parent.offsetTop; } Return a new rectangle (left, top, elem.offsetwidth, elem.offsetHeight); }  

The only remaining problem is that the above and left properties do not compensate for the size of the browser window's "chrome", so the element screenshot should be downwards and downwards .

As long as I understand how to compensate for this, I am saving it from setting the browser in "full screen" mode before taking it.


Comments