In Codedui how to scroll a page vertically by required pixel

旧街凉风 提交于 2019-12-12 04:59:58

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/24059419/in-codedui-how-to-scroll-a-page-vertically-by-required-pixel

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