While doing a codedUi test I want to run a simple javascript which scrolls the page window.scrollBy(0,500)
. I am using VS2010. How can i achieve that.
I tried a lot of native ways for scrolling web page, but none are working. Thought of trying javascript way, but don't know how to do. Only thing that worked is sending PageDown key, but that won't help me in pixel perfect scrolling. So this question actually becomes a subset of "How can i scroll a page in codedui".
Any suggestion would be helpful.
There's probably a better solution for this, but this is how I got it to work:
First, add reference to Microsoft.mshtml. Then record the body (or document) part of the webpage and add it to the UIMap. Let's say it's accessed by this.UIMap.UIBrowser.UIBody
. Add the following code:
var nativeBody = this.UIMap.UIBrowser.UIBody.NativeElement;
var window = ((nativeBody as HTMLBody).document as mshtml.HTMLDocument).parentWindow;
The window
should be the COM object you can use for scripting. Like:
window.scrollBy(0, 50);