I
I
Ivan Yakushenko2019-06-06 14:37:11
Python
Ivan Yakushenko, 2019-06-06 14:37:11

How to move a line from Selenium to WhatsApp when sending a message?

Send message function:

template = {
    'other': 
             'Текст.'
             'Еще текст.'
             'И еще текст.'
             'Все, последний текст.'
}


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, the required response is taken from the template and passed to send_message() as the answer argument .
If you send a message as is, then in WhatsApp it comes in one line:
Text.More text.And more text.That's it, the last text.

If you add \n then each line will be sent as a new message, i.e. more or less like this:
5cf8faa8701b5547068844.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2019-06-06
@kshnkvn

Sim3x helped in the solution

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()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question