How to line break in WhatsApp with Selenium when sending a message? How to line break in WhatsApp with Selenium when sending a message? selenium selenium

How to line break in WhatsApp with Selenium when sending a message?


Solved this

def send_message(driver, answer):    driver.find_element_by_xpath('XPATH').click()    for line in answer.split('\n'):        ActionChains(driver).send_keys(line).perform()        ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.ENTER).perform()    ActionChains(driver).send_keys(Keys.RETURN).perform()


You can use the following code to add the line. It is working fine and I am using it in my ERP.

smsContain = "*Greetings from  " + cname + " ,%0a %0a M/s. " + txtName.Text + " %0a %0a


This worked for me. Basically pressing SHIFT+ENTER every time a new line appears.

MESSAGE = """This is a sample message.It accepts one new line.also accepts multiple new lines as well."""for one_line in MESSAGE.split("\n"):    driver.find_element('').send_keys(one_line)    driver.find_element('').send_keys(Keys.SHIFT + Keys.ENTER)driver.find_element('').send_keys(Keys.ENTER)