How to scroll Firefox and IE in WatiN?

How to scroll Firefox and IE in WatiN?

+6
source share
1 answer

You can call the scrollIntoView method for Internet Explorer or FireFox for any 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"); } 

Similarly, if you need the position of an 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(); } 
+9
source

Source: https://habr.com/ru/post/888898/


All Articles