Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With WatiN, it is possible to get to the "native" interface of elements in IE windows. Using that you can get the screen coordinates of any element.</p> <pre><code>using mshtml; //Add a reference to Microsoft.mshtml that comes with WatiN. using WatiN.Core.Native.InternetExplorer; public static 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); } </code></pre> <p>To use it:</p> <pre><code>Button myButton = browser.Button(Find.ById("myButton")); System.Drawing.Point clickPoint = GetScreenPoint((IEElement)myButton.NativeElement); MyClick(clickPoint); </code></pre> <p>Obviously the element has to be visible. I don't know how to check for that offhand, but I think you can change the scrollTop and scrollLeft attributes of the body to scroll around.</p> <p>You'll also need a method to actually do the click, but there's probably an answer for that already on stackoverflow.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload