开发者

How to scroll Firefox and IE in WatiN?

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜