How to scroll Firefox and IE in WatiN?

穿精又带淫゛_ 提交于 2019-12-21 12:37:18

问题


How to scroll Firefox and IE in WatiN?


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!