Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用VS 2012在编码UI测试中滚动网页?_C#_Visual Studio 2012_Coded Ui Tests - Fatal编程技术网

C# 如何使用VS 2012在编码UI测试中滚动网页?

C# 如何使用VS 2012在编码UI测试中滚动网页?,c#,visual-studio-2012,coded-ui-tests,C#,Visual Studio 2012,Coded Ui Tests,我正在用VS 2012记录编码的UI测试,它将测试web应用程序的功能 在我加载网页后,我点击一个按钮来启动一个工作申请 在同一站点上加载下一页后,我的问题就开始了。 入口控件位于网站的末尾。 要查看并将数据输入入口控件,我必须向下滚动。 录制在UIMap中产生以下方法 Designer.cs: public void Scrollen() { #region Variable Declarations Playback.PlaybackSettings.WaitForReady

我正在用VS 2012记录编码的UI测试,它将测试web应用程序的功能

在我加载网页后,我点击一个按钮来启动一个工作申请

在同一站点上加载下一页后,我的问题就开始了。 入口控件位于网站的末尾。 要查看并将数据输入入口控件,我必须向下滚动。 录制在UIMap中产生以下方法

Designer.cs:

public void Scrollen()
{
    #region Variable Declarations
    Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
    this.UIGoogleMozillaFirefoxWindow.UIItemPropertyPage.UIBewerbungDemoFirmaDocument.WaitForControlExist();
    this.UIGoogleMozillaFirefoxWindow.UIItemPropertyPage.UIBewerbungDemoFirmaDocument.WaitForControlReady();
    Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
    WinControl uIBewerbungDemoFirmaDocument = this.UIGoogleMozillaFirefoxWindow.UIItemPropertyPage.UIBewerbungDemoFirmaDocument;
    #endregion

    // Click "Job application" document
    Point pt = new Point(1390, 553);
    int count = 0;
    while (!uIBewerbungDemoFirmaDocument.TryGetClickablePoint(out pt) && count < 20)
    {
        count++;
        System.Threading.Thread.Sleep(10);

        if (count == 20)
            Console.WriteLine("ClickablePoint not found");
    }

    Mouse.Click(uIBewerbungDemoFirmaDocument, new Point(1390, 553));
    Mouse.MoveScrollWheel(10);
}
如您所见,我尝试了WaitForControlExist、WaitForControlReady、TryGetClickablePoint和方法MoveScrollWheel。 但Mouse.Click和Mouse.MoveScrollWheel都不工作

在下一个方法中,我点击第一个输入字段,我在执行时得到一条消息,点击事件会产生一个错误,因为控件是隐藏的,因为它位于网站下方,超出了可见范围。 经过几次测试,我都快疯了


你知道哪里出了问题,我怎样才能向下滚动网站,使我的入口控件在可见范围内吗?

你可以试试Control.EnsureClickable。或者您可以使用下面提到的功能滚动页面,直到控件无法单击为止

public static void ScrollAndClick(HtmlControl Control)
    {
        bool isClickable = false;
        if (Control.TryFind())
        {
            while (!isClickable)
            {
                try
                {
                    Control.EnsureClickable();
                    Mouse.Click(Control);
                    isClickable = true;
                }
                catch (FailedToPerformActionOnHiddenControlException)
                {
                    Mouse.MoveScrollWheel(-1);
                    throw;
                }

            }
        }
        else
        {
            throw new AssertInconclusiveException("Control Not Found");
        }

    }
您还可以添加与超时相关的条件,以确保它不会进入无限循环


如果您对此有疑问,请告诉我。

你好,库尔德普,谢谢您的回答,但这并没有真正的帮助。当我使用要导航到的HtmlButton调用该方法时,我会在Control.EnsureClickable.is控件上获得UITestControlNotVisibleException。因为这种类型的异常通常是由于页面加载问题而发生的。在EnsureClickable方法之前,我执行WaitForControlExist和WaitForControlReady。正常情况下,控件应该存在并准备好进行输入操作,不是吗?是的,如果在调试模式下进行了检查,则是这样。在确保可链接控件对象与各种值绑定或显示为Null之前。WaitforcontrolExit和WaitforControlReady在获得实际控制之前可能会超时。我找到了另一种方法来执行并记录这一操作。加载页面后,我单击滚动条并使用向上或向下光标按钮。