开发者

How to scroll Firefox and IE in WatiN?

开发者 https://www.devze.com 2023-03-08 04:45 出处:网络
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:

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

精彩评论

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