在将键盘按键发送到Outlook消息窗口期间,如何避免编码UI中的PlaybackFailureException?

时间:2018-07-21 12:52:23

标签: outlook coded-ui-tests

我正在尝试将键盘序列ctrl + c发送到Outlook会议形式的消息字段(ControlType = Client; Name = Message),并获取PlaybackFailureException。

发现该元素成功,我可以在那里发送任何文本,但是不能发送键盘键。我尝试了两种方法:

1)使用修饰符:

elements_object.SetFocus();
Keyboard.SendKeys("{A}", ModifierKeys.Control);
Keyboard.SendKeys("{C}", ModifierKeys.Control);

这样,只需在字段中键入A,然后键入C。我预期未执行的操作(选择+复制)

2)不带修饰符:

elements_object.SendKeys("{^a}");
elements_object.SendKeys("{^c}");

这种方式引发了异常PlaybackFailureException。

有趣的是:例如发送{ENTER}是可行的。

伙计们,我在做什么错了?

2 个答案:

答案 0 :(得分:1)

如果要执行Ctrl + A,请使用

Keyboard.SendKeys("^a");

要执行Ctrl + C,

Keyboard.SendKeys("^c");

如果要传递控制权,必须执行sendkeys:

  Keyboard.SendKeys(UITestControl, "^c");

点击此处了解有关SendKeys的更多信息:MSDN SendKeys

修改

我尝试了以下代码(可能很快又很脏),它对我有用:

 WinWindow outlook = new WinWindow();
        outlook.SearchProperties.Add(WinWindow.PropertyNames.Name, "Untitled - Meeting  ");
        WinClient doc = new WinClient(outlook);
        doc.SearchProperties.Add(WinWindow.PropertyNames.Name, "Document1");
        WinClient msg = new WinClient(doc);
        msg.SearchProperties.Add(WinWindow.PropertyNames.Name, "Message");

        Keyboard.SendKeys(msg, "^a");
        Keyboard.SendKeys(msg, "^c");
// I tried pasting it, it pastes same content whatever is copied.
        Keyboard.SendKeys(msg, "^v");

答案 1 :(得分:0)

我不知道它是如何工作的,但是也许将来对某人有用。方法是单击此字段,然后所有快捷方式都可以正常工作。如果不单击,则不起作用。