How to scroll Firefox and IE in WatiN?
You can call the "scrollIntoView" method for either Internet Explorer or FireFox for any given element using the following code:
For Internet Explorer:
using (var browser = new IE("http://www.google.com"))
{
var textField = browser.TextField(Find.ByName("q"));
var nativeElement = textField.NativeElement as IEElement;
nativeElement.AsHtmlElement.scrollIntoView();
}
For FireFox:
using (var browser = new IE("http://www.google.com"))
{
var textField = browser.TextField(Find.ByName("q"));
var nativeElement = textField.NativeElement as JSElement;
nativeElement.ExecuteMethod("scrollIntoView");
}
Likewise, if you want the position of the element, you can use the same code, but instead of calling scrollIntoView(), you can call offsetLeft() and offsetTop() to get the position.
using (var browser = new IE("http://www.google.com"))
{
var textField = browser.TextField(Find.ByName("q"))
var nativeElement = textField.NativeElement as IEElement;
int leftoffset = nativeElement.AsHtmlElement.offsetLeft();
int topoffset = nativeElement.AsHtmlelement.offsetTop();
}
来源:https://stackoverflow.com/questions/6109776/how-to-scroll-firefox-and-ie-in-watin