DropdownLookupFilter

public DropdownLookupFilter()
{
    Require(stack =>
    {
        AXUtils.LoadManager("MSAA");
        return stack.Peek().UIElement.ControlTypeName == "Cell" &&
            stack.Count >= 2 &&
            stack.Peek(1).UIElement != null &&
            stack.Peek(1).UIElement.Name.Contains("lookup button");
    });
}
This filter only acts when you've just clicked on something in a dropdown list. To determine this, we first just make sure you're clicking on a grid (the results of the dropdown). Then we look at the stack to make sure that the grid the user is clicking on came from a dropdown button.

protected override void Run(IUITestActionStack stack)
{
    var topLevel = stack.Peek(1).UIElement.TopLevelElement;
    // Find the cell itself.
    var value = stack.Peek(1).UIElement.Parent().Parent();
    stack.Pop();
    stack.Pop();

    var sendKeys = new SendKeysAction(new UITechnologyElementRedirect(
        value, topLevel,
        Playback.GetCoreTechnologyManager("MSAA"), "MSAA"));
    // The lookup dialog will have set the cell value now,
    // so we can just remember what it was set to.
    sendKeys.Text = "{Ctrl}{Left}{Shift}{Ctrl}{Right}" + value.Value + "{Enter}";
    stack.Push(sendKeys);
    sendKeys = new SendKeysAction();
    sendKeys.Text = "{Shift}{Tab}";
    stack.Push(sendKeys);
}
Once we've encountered a dropdown lookup, we grab the elements that the user is interacting with. By this time, the dropdown has disappeared and applied its value, so we can just set the SendKeys text to the target's value. We also have to select the text in the cell before typing, which is what the blob of action keys at the beginning of the text is for. To finalize the cell's value, we hit enter afterward, but must then hit shift+tab to bring the focus back to the element.

Last edited Aug 1, 2014 at 7:25 PM by wgoodin, version 4