Search code examples
numberswinappdriver

WinAppDriver / AZERTY Keyboard : sendkeys() doesn't send correctly the numbers


I try to use WinAppDriver for my UI test. Sendkeys() sends QWERTY txt, while I use AZERTY layout.

I manage to relace characters this way but it doesn't work for numbers:

public static async Task<WindowsElement> SendKeyAndWait(this WindowsElement element, string azertyText, int secondsToWaitAfter = 0, int secondsToWaitFirst = 1)
        {
            await element.ClickAndWait(secondsToWaitFirst);
            element.SendKeys(azertyText
                .Replace("a", "q")
                .Replace("m", ";")
                .Replace("z", "w")
                .Replace(",", "m")  //WinAppDriver ne connait que le clavier qwerty donc q => a
                .Replace("1", "&")  //semble ne pas fonctionner pour les chiffres
                .Replace("0", "à")
                );
            await Task.Delay(secondsToWaitAfter);
            return element;
        }      

Has anyone already solved this issue ?
Thanks for your answers

Solution

  • This issue is raised and still open (4 years!) on the WinAppDriver repo.

    Here's the workaround that a user suggested there.

    private static void SwitchToUsKeyboard()
    {
        var switchKeyboardLayoutActions = new Actions(AppSession);
        switchKeyboardLayoutActions.SendKeys(Keys.Control + "0" + Keys.Control);
        switchKeyboardLayoutActions.Build();
        switchKeyboardLayoutActions.Perform();
    }
    
    private static void SwitchToFrKeyboard()
    {
        var switchKeyboardLayoutActions = new Actions(AppSession);
        switchKeyboardLayoutActions.SendKeys(Keys.Control + "1" + Keys.Control);
        switchKeyboardLayoutActions.Build();
        switchKeyboardLayoutActions.Perform();
    }
    

    You would have to setup the US language with a US keyboard first (as well as French in this example). Then you need to add shortcuts for these keyboards.

    enter image description here