Message sending function:
template = {
'other':
'Text.'
'More Text.'
'Much more text.'
}
def send_message(driver, answer):
driver.find_element_by_xpath('XPATH').click()
action = ActionChains(driver)
action.send_keys(answer)
action.send_keys(Keys.RETURN)
action.perform()
Depending on the received message from the template
, the necessary answer is taken and passed to send_message()
as the answer
argument.
If you send the message as is, then in WhatsApp it comes in one line:
Text.More text.Much more text.
If you add \n
then each line will be sent with a new message, i.e. like that:
screenshot of sent message
How can I send text with line breaks in one 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With