3

I'm having trouble with sending a backslash character using WinAppDriver and Appium. When I use send.keys to send a backslash character, a '#' character is sent in it's place. I have tried in numerous ways (shown below).

Appium v 0.28

WinnAppDriver v 1.1.1809.18001

from appium import webdriver

desired_caps = {'app': 'Root', 'autoLaunch': 'false'}
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723',
                               desired_capabilities=desired_caps)
w1 = driver.find_element_by_name('Untitled - Notepad')
for elem in w1.find_elements_by_name('Text Editor'):
    elem.send_keys(chr(92))
    elem.send_keys('\\')
    elem.send_keys(r'C:\test')
Trevor Fuller
  • 93
  • 1
  • 6

2 Answers2

2

This is currently a bug. (Read more about it here for example.)

You cannot send \ as a string if you don't use US keyboard layout. For a dirty workaround, you can type the character via it's ASCII code by pressing ALT, then the numbers 9 and 2, then releasing ALT, as is being described here:

Keys.Alt + Keys.NumberPad9 + Keys.NumberPad2 + Keys.Alt
finefoot
  • 9,914
  • 7
  • 59
  • 102
  • Unfortunately, this won't work on a SaveAs dialog window when setting the path if num lock isn't active (as the 2 key is a shortcut on the SaveAs dialog). Tried on Windows 11 on a WPF application. – Mickael Bergeron Néron May 16 '23 at 05:30
0

Using a UK Keyboard and Windows 11 and C#, I had this problem. I tried to populate a Textbox with a Windows filepath which had several sub-folders:-

  • Using String.Normalize() - no luck, # remained a #
  • Inserting the Unicode for Backslash (u005C) - it got converted to #

The solution was to temporarily switch to a US Keyboard by defining 2 cultures, a US one and a UK one:-

CultureInfo CultureInfoUS = CultureInfo.CreateSpecificCulture( "en-US" );
CultureInfo CultureInfoUK = CultureInfo.CreateSpecificCulture( "en-UK" );

and then bracketing the Appium .SendKeys() methods on the way in with:

InputLanguage.KeyBoardLanguage = InputLanguage.FromCulture(CultureInfoUS);
InputLanguage.CurrentInputLanguage = KeyBoardLanguage;

so that my keyboard was a US one, and on the way out with:

InputLanguage.KeyBoardLanguage = InputLanguage.FromCulture(CultureInfoUK);
InputLanguage.CurrentInputLanguage = KeyBoardLanguage;

so that my keyboard was reset to a UK one.

Tony H
  • 61
  • 3