CodedUI Test: Keyboard.SendKeys not working

…衆ロ難τιáo~ 提交于 2019-12-08 08:16:30

问题


I'm trying to use the CodedUI Test feature of Visual Studio 2010. I've got a problem while replaying the various actions for one of my html component. The Keyboard.SendKeys generated do not work (like if there was no input).

The code generated is :

// Type '{F4}{F4}{F2}titre{Enter}' in 'SaisieSD_DS' custom control
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);

If I replace the call to Keyboard.SendKeys by a call to System.Windows.Forms.SendKeys.SendWait, it does work.

I was thinking about a problem due to a loss of focus. However, if i do something like uISaisieSD_DSCustom.SetFocus(), it doesn't change the behavior.

Do you have any idea ?

thx.


回答1:


Have you tried

uISaisieSD_DSCustom.WaitForReady()

Or one of the other waitfors?

Is it failing on this line? Or is it failing afterward due to this not working correctly?

You can also use the following to wait for all threads to complete before proceeding:

Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;

Just make sure you include the last line to turn it back to UIThreadOnly, or it will slow everything way down.




回答2:


Visual Studio CodedUI Test searches for a control and sends those keys to it. In your case the control is 'uISaisieSD_DSCustom'. You can try using:

Keyboard.SendKeys(this.Params.UISaisieSD_DSCustomSendKeys);

OR

Keyboard.SendKeys("{F4}{F4}{F2}titre{Enter}");



回答3:


After typing the URL if we want to send the enter key then the below code works in Coded UI

Keyboard.SendKeys("{Enter}");


来源:https://stackoverflow.com/questions/4014218/codedui-test-keyboard-sendkeys-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!