使用Watin移动ExtJS网格列

时间:2011-06-16 12:00:08

标签: c# extjs watin

正如标题所暗示的那样,我一直试图触发一个onmousedown偶然然后在列标题上的onmmousemove事件来模拟拖放。 onmousedown似乎“点击”该项目(它变黄)但没有移动。

我正在使用这里的概念http://www.codeproject.com/KB/aspnet/watinajaxtest.aspx

任何想法。

var columnHeaderToMove = browser.Div(Find.ById("listings")).TableCell(l => l.Text == "Title").ChildWithTag("div", null);

        var mouseDownEvent = new NameValueCollection();
        mouseDownEvent.Add("button", "1");
        mouseDownEvent.Add("clientX", "0");
        mouseDownEvent.Add("clientY", "0");
        columnHeaderToMove.FireEventNoWait("onmousedown", mouseDownEvent);
        Thread.Sleep(500);

        var columnHeaderToMoveTo = browser.Div(Find.ById("listings")).TableCell(l => l.Text == "Person");
        int Left = int.Parse(columnHeaderToMoveTo.GetAttributeValue("offsetLeft"))
        var eventProperties = new NameValueCollection();
        eventProperties.Add("button", "1");
        eventProperties.Add("clientX", Left.ToString());
        eventProperties.Add("clientY", "0");

非常感谢

1 个答案:

答案 0 :(得分:0)

好几个小时尝试各种各样的东西后,我解决了它。代码在这里帮助其他人

var columnRowHeader = browser.Div(Find.ById(listingId)).Element(Find.ByClass("x-grid3-header-inner", false));
        var gridBody = browser.Div(Find.ById(listingId)).Element(Find.ByClass("x-panel-body", false));

        var gridPanel = browser.Div(Find.ById(listingId));
        var columnHeaderToMove = browser.Div(Find.ById(listingId)).TableCell(l => l.Text == "Title").ChildWithTag("div", null);

        int CurrentX = this.helper.FindPosition(columnHeaderToMove)[0];
        int CurrentY = this.helper.FindPosition(columnHeaderToMove)[1];

        var mouseDownEvent = new NameValueCollection();
        mouseDownEvent.Add("button", "1");
        mouseDownEvent.Add("clientX", "459");
        mouseDownEvent.Add("clientY", "115");
        columnHeaderToMove.FireEventNoWait("onmousedown", mouseDownEvent);
        Thread.Sleep(500);

        var columnHeaderToMoveTo = browser.Div(Find.ById(listingId)).TableCell(l => l.Text == "Person Responsible");
        //int newX = this.helper.FindPosition(columnHeaderToMoveTo)[0];
        //int newY = this.helper.FindPosition(columnHeaderToMoveTo)[1];
        int newX = 670;

        var eventProperties = new NameValueCollection();
        eventProperties.Add("button", "1");
        eventProperties.Add("clientX", newX.ToString());
        eventProperties.Add("clientY", "115");

        columnHeaderToMove.FireEventNoWait("onmousemove", eventProperties);
        Thread.Sleep(1000);

        //mouse up
        var mouseUpEvent = new NameValueCollection();
        mouseUpEvent.Add("button", "1");
        mouseUpEvent.Add("clientX", newX.ToString());
        mouseUpEvent.Add("clientY", "115");

        columnHeaderToMoveTo.FireEventNoWait("onmouseup", mouseUpEvent);
        columnHeaderToMove.FireEventNoWait("onmouseup", mouseUpEvent);

        Thread.Sleep(2000);

        int finalX = this.helper.FindPosition(columnHeaderToMove)[0];
        Assert.IsTrue(finalX != CurrentX, "Left was {0} is now {1} should be {2}.", CurrentX, finalX, newX);