如何在WatiN中滚动Firefox和IE? [英] How to scroll Firefox and IE in WatiN?

查看:56
本文介绍了如何在WatiN中滚动Firefox和IE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在WatiN中滚动Firefox和IE?

How to scroll Firefox and IE in WatiN?

推荐答案

您可以使用以下代码针对任何给定元素为Internet Explorer或FireFox调用"scrollIntoView"方法:

You can call the "scrollIntoView" method for either Internet Explorer or FireFox for any given element using the following code:

对于Internet Explorer:

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

对于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");
}

同样,如果需要元素的位置,则可以使用相同的代码,但是可以调用offsetLeft()和offsetTop()来代替位置,而不必调用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();
}

这篇关于如何在WatiN中滚动Firefox和IE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆