在Codedui中如何按所需像素垂直滚动页面 [英] In Codedui how to scroll a page vertically by required pixel

查看:140
本文介绍了在Codedui中如何按所需像素垂直滚动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行codedUi测试时,我想运行一个简单的javascript来滚动页面 window.scrollBy(0,500)。我正在使用VS2010。我怎样才能实现这一目标。

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.

我尝试了许多本地滚动网页的方法,但没有一种方法可行。想到尝试javascript方式,但不知道该怎么做。唯一有用的是发送PageDown键,但这对像素完美滚动没有帮助。所以这个问题实际上成了如何在codedui中滚动页面的子集。

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:

首先,添加对Microsoft.mshtml的引用。然后记录网页的正文(或文档)部分并将其添加到UIMap。假设它是由 this.UIMap.UIBrowser.UIBody 访问的。添加以下代码:

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;

窗口应该是你的COM对象可以用于编写脚本。喜欢:

The window should be the COM object you can use for scripting. Like:

window.scrollBy(0, 50);

这篇关于在Codedui中如何按所需像素垂直滚动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆