2

I need to fill the body of an email client application on a real smartphone. I am using Python 3.7 + Appium.

I tried to send_keys a text with '\n' for each new line but it didn't work.

This is the string:

text="Bonjour {username},\nJe recherche des testeurs pour un nouveau logiciel marketing.\\nVoudriez-vous le tester?\nCordialement."

and when I do send_keys:

p_body.send_keys(text)

it fill the textarea as a single line with the string \n inside the text. it doesn't lake 'new line'. :-(

I could try with ActionChains, but it doesn't accept the special characters with accents.

Anyone already tried to fill a paragraph of multiple lines in an input with Appium and send_keys?

Gauthier Buttez
  • 1,005
  • 1
  • 16
  • 40
  • Did the `\\n` show up also or just the single backslash? On some systems you need `\r\n` (escaped would be `\\r\\n` to output a carriage return. See if those work. – JeffC Mar 03 '20 at 05:29

2 Answers2

2

To fill the body of an email client application using send_keys including \n for each new line you can use the execute_script() method as follows:

p_body = driver.find_element_by_id('element_id')
text = "Bonjour {username},\nJe recherche des testeurs pour un nouveau logiciel marketing.\\nVoudriez-vous le tester?\nCordialement."
driver.execute_script('arguments[0].value=arguments[1]', p_body, text)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Hi fellow french stackoverflow user ;)

According to Tamas Hegedus on this post : Selenium Webdriver enter multiline text in form without submitting it, you can try to replace the /n with Keys.chord(Keys.SHIFT, Keys.ENTER)

Hope it helps

EDIT

This solution doesn't work for Python, but for Java. The right answer, as said in Error: type object 'Keys' has no attribute 'chord', is using ActionChains

MatthiasDec
  • 145
  • 1
  • 11