static void Main(string[] args) { Browser browser = new IE("http://www.google.com"); IEElement banner = browser.Images[0].NativeElement as IEElement; IHTMLElement bannerHtmlElem = banner.AsHtmlElement; IEElement bodyNative = browser.Body.NativeElement as IEElement; mshtml.IHTMLElement2 bodyHtmlElem = (mshtml.IHTMLElement2)bodyNative.AsHtmlElement; mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)bodyHtmlElem.createControlRange(); controlRange.add((mshtml.IHTMLControlElement)bannerHtmlElem); controlRange.execCommand("Copy", false, System.Reflection.Missing.Value); controlRange.remove(0); if (Clipboard.GetDataObject() != null) { IDataObject data = Clipboard.GetDataObject(); if (data.GetDataPresent(DataFormats.Bitmap)) { System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true); // do something here } } }
public IEDocument(IHTMLDocument2 htmlDocument, IEElement containingFrameElement) { if (htmlDocument == null) throw new ArgumentNullException("htmlDocument"); this.htmlDocument = htmlDocument; this.containingFrameElement = containingFrameElement; }
public IEElementCollection(IEnumerable htmlElementCollection, IEElement element) { if (htmlElementCollection == null) throw new ArgumentNullException("htmlElementCollection"); _htmlElementCollection = htmlElementCollection; _element = element; }
public void Process(IWebBrowser2 webBrowser2) { // Get the frame element from the parent document var uniqueId = RetrieveUniqueIdOfFrameElement(); var frameElement = RetrieveSameFrameFromHtmlDocument(uniqueId); var nativeFrameElement = new IEElement(frameElement); Elements.Add(new IEDocument((IHTMLDocument2) webBrowser2.Document, nativeFrameElement)); index++; }
private static int position(Element element, string attributename) { IEElement ieElement = (IEElement)element.NativeElement; var pos = 0; var offsetParent = ieElement.AsHtmlElement.offsetParent; if (offsetParent != null) { var domContainer = element.DomContainer; pos = position(new Element(domContainer, new IEElement(offsetParent)), attributename); } if (StringComparer.AreEqual(element.TagName, "table", true)) { pos = pos + int.Parse(element.GetAttributeValue("client" + attributename)); } return(pos + int.Parse(element.GetAttributeValue("offset" + attributename))); }
// System drawing point leveraged to get coordinates // using System.Drawing and mshtml /// <summary> /// Method to get Grid Coordinates of an element /// </summary> /// <param name="element"></param> /// <returns></returns> public System.Drawing.Point GetScreenPoint(IEElement element) { IHTMLElement nativeElement = element.AsHtmlElement; IHTMLElement2 offsetElement = (IHTMLElement2)nativeElement; IHTMLRect clientRect = offsetElement.getBoundingClientRect(); IHTMLDocument2 doc = (IHTMLDocument2)nativeElement.document; IHTMLWindow3 window = (IHTMLWindow3)doc.parentWindow; int windowLeft = window.screenLeft; int windowTop = window.screenTop; int elementLeft = clientRect.left; int elementTop = clientRect.top; int width = nativeElement.offsetWidth; int height = nativeElement.offsetHeight; int clickX = windowLeft + elementLeft + (width / 2); int clickY = windowTop + elementTop + (height / 2); return new System.Drawing.Point(clickX, clickY); }
// System drawing point leveraged to get coordinates // using System.Drawing and mshtml /// <summary> /// Method to get Grid Coordinates of an element /// </summary> /// <param name="element"></param> /// <returns></returns> public System.Drawing.Point GetScreenPoint(IEElement element) { IHTMLElement nativeElement = element.AsHtmlElement; IHTMLElement2 offsetElement = (IHTMLElement2)nativeElement; IHTMLRect clientRect = offsetElement.getBoundingClientRect(); IHTMLDocument2 doc = (IHTMLDocument2)nativeElement.document; IHTMLWindow3 window = (IHTMLWindow3)doc.parentWindow; int windowLeft = window.screenLeft; int windowTop = window.screenTop; int elementLeft = clientRect.left; int elementTop = clientRect.top; int width = nativeElement.offsetWidth; int height = nativeElement.offsetHeight; int clickX = windowLeft + elementLeft + (width / 2); int clickY = windowTop + elementTop + (height / 2); return(new System.Drawing.Point(clickX, clickY)); }
public string getElementDimensions(IEElement element) { var htmlElement = element.AsHtmlElement; if (htmlElement.offsetParent == null) return string.Empty; var left = htmlElement.offsetLeft; var top = htmlElement.offsetTop; var width = htmlElement.offsetWidth; var height = htmlElement.offsetHeight; do { htmlElement = htmlElement.offsetParent; left += htmlElement.offsetLeft; top += htmlElement.offsetTop; } while (htmlElement.offsetParent != null); return "left:" + left + " right:" + (left + width) + " top:" + top + " bottom: " + (top + height) + " width: " + width + " height:" + height; }
public void BodyShouldReturnAnIENativeElement() { // GIVEN var htmlElementMock = new Mock <IHTMLElement>(); var htmlElement = htmlElementMock.Object; var htmlDocument2Mock = new Mock <IHTMLDocument2>(); htmlDocument2Mock.Expect(document => document.body).Returns(htmlElement); var htmlDocument = htmlDocument2Mock.Object; var ieDocument = new IEDocument(htmlDocument); // WHEN var nativeElement = ieDocument.Body; // THEN IEElement ieElement = (IEElement)nativeElement; Assert.That(ReferenceEquals(ieElement.AsHtmlElement, htmlElement), "Unexpected instance"); }
public string getElementDimensions(IEElement element) { var htmlElement = element.AsHtmlElement; if (htmlElement.offsetParent == null) { return(string.Empty); } var left = htmlElement.offsetLeft; var top = htmlElement.offsetTop; var width = htmlElement.offsetWidth; var height = htmlElement.offsetHeight; do { htmlElement = htmlElement.offsetParent; left += htmlElement.offsetLeft; top += htmlElement.offsetTop; }while (htmlElement.offsetParent != null); return("left:" + left + " right:" + (left + width) + " top:" + top + " bottom: " + (top + height) + " width: " + width + " height:" + height); }
public IEFireEventHandler(IEElement ieElement) { _ieElement = ieElement; }
public static void Hide(this Element element) { IEElement el = element.NativeElement as IEElement; el.AsHtmlElement.style.display = "none"; }
public static void Show(this Element element) { IEElement el = element.NativeElement as IEElement; el.AsHtmlElement.style.display = "block"; }