Text formatting issue using SendKey() + WhatsApp

I am using Appium to send messages through WhatsApp, but are facing some text formatting challenges while sending the messages, whereby some line breaks and spaces are removed when the message is parsed via Appium into the Whatsapp UI. The messages are sent with links and emoji’s using appium and Java, but line breaks and spaces are often (not always) removed while typing the message into the WhatsApp UI using “SendKey()” function.

I have set the Unicode keyboard capability to support the emoji’s and other languages like Arabic. The Appium version 1.6.4. is used here.

Has anyone else experienced issues with text formatting like this, when using Appium?

Below is the code snippet and screen shot of original message and phone message for more context:

snippet1

Original Message (Example text):
Welcome to the test application.

This is test link 1
http://bit.ly/2Csqvqo
This is test link 2
http://bit.ly/2AvXqcj
This is test link 3
http://bit.ly/2jVAnkT_TESTING
This is test link 4
http://bit.ly/2j4jvHG

Thanks from the test application

Any help you can provide would be greatly appreciated. Thanks in Advance!

Hi i am trying to automate whatsapp setup, hear i am unable to enter phone number.

Check the code:
#import appium
import time
from appium import webdriver

desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘platformVersion’] = ‘8.0.0’
desired_caps[‘deviceName’] = ‘23fbda3d’
#desired_caps[‘NO_RESET’] = ‘true’
#desired_caps[‘FULL_RESET’] = ‘false’
#desired_caps[‘app’] = ‘C:/Users/rbandapalli/Downloads/ApiDemos-debug.apk’
#desired_caps[‘app’] = ‘C:/Users/rbandapalli/Documents/qa/GM_Stability/apks/WhatsApp.apk’
desired_caps[‘appPackage’] = ‘com.whatsapp’
desired_caps[‘appActivity’] = ‘com.whatsapp.HomeActivity t475’
driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
print(driver)
time.sleep(3)

driver.find_element_by_xpath("//android.widget.Button[@text=‘AGREE AND CONTINUE’]").click()
time.sleep(2)
driver.find_element_by_xpath("//android.widget.Button[@text=‘CONTINUE’]").click()
time.sleep(2)
driver.find_element_by_xpath("//android.widget.Button[@text=‘ALLOW’]").click()
driver.find_element_by_xpath("//android.widget.Button[@text=‘ALLOW’]").click()
time.sleep(2)
#driver.hide_keyboard()
driver.find_elements_by_xpath("//android.widget.EditText[@text=‘phone number’]").click().send_keys(“1234”)
#driver.find_element_by_android_uiautomator(‘new UiSelector().text(“phone number”)’).sendkeys(“12345678”)
#driver.find_element_by_id(“com.whatsapp:id/registration_phone”).click().sendkeys(“123456”)
elem = driver.switch_to.active_element
#print(element.sizeof())
#driver.find_element_by_android_uiautomator(“new UiScrollable(new UiSelector()).scrollIntoView(text(“phone number”));”).click().send_keys(“1234567”)
#driver.find_element_by_xpath("//android.widget.EditText[@index=‘4’]").click().clear()
#driver.find_element_by_xpath("//*[@id=‘com.whatsapp:id/registration_phone’]").click().send_keys(“1234567”)
time.sleep(2)
driver.find_element_by_xpath("//android.widget.Button[@text=‘NEXT’]").click()
time.sleep(5)
#driver.quit()

Can some one help me how to enter phone number ?

Make sure you are using uiautomator2. Also if send keys directly on element doesn’t work, try to click it first, then send the keys.

Finally you may use ADB directly to send the text to active edittext