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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With