I was creating a program to automatically send messages via WhatsApp, but I have a very annoying problem. I want to send a large text for dissemination, when I put the program to work, it opens WhatsApp, I scan the QR CODE, it searches the groups and sends messages, but sends it as if it were several messages. What I want is for you to send a message with the entire text. I live in Brazil and I’m using google translator to write this question, sorry for the spelling errors.
# importar as bibliotecas
from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
# navegar até o WhatsApp web
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://web.whatsapp.com/')
time.sleep(15)
# Definir contatos e grupos e msg para ser enviado
contatos = ['test 1', 'test 2', 'test 3']
mensagem = '''
PLANTÕES DISPONÍVEIS
Plantão de 12h apenas Diurno das 07:00h as 19:00h
Julho
19/07 - Segunda Feira
26/07 - Segunda Feira
Agosto
02/08 - Segundo Feira
09/08 - Segunda Feira
16/08 - Segunda Feira
23/08 - Segunda Feira
30/08 - Segunda Feira
Pagamento semanal liquido!
INTERESSADOS
Vinícius
OBSERVAÇÕES
Boa estrutura, local muito bom para fazer plantão
'''
# buscar contato ou grupo
def buscar_contato(contato):
campo_pesquisa = driver.find_element_by_xpath('//div[contains(@class,"copyable-text selectable-text")]')
time.sleep(1)
campo_pesquisa.click()
campo_pesquisa.send_keys(contato)
campo_pesquisa.send_keys(Keys.ENTER)
def enviar_mensagem(mensagem):
campo_mensagem = driver.find_elements_by_xpath('//div[contains(@class,"copyable-text selectable-text")]')
campo_mensagem[1].click()
time.sleep(1)
campo_mensagem[1].send_keys(mensagem)
campo_mensagem[1].send_keys(Keys.ENTER)
for contato in contatos:
buscar_contato(contato)
enviar_mensagem(mensagem)
# Campo de pesquisa 'copyable-text selectable-text'
# Campo de msg privado 'copyable-text selectable-text'
# enviar mensagem para contato ou grp
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there
I recently made a python library that abstracts selenium and provides an easy and intuitive interface plus advanced control over the WhatsApp Web, you really wanna have a look at it, I’m pretty sure you will love it
Here is a link https://github.com/Kalebu/alright
Here how to send a message to the user
Thank you Kalebu
Hello,
According to the official WhatsApp documentation, the maximum limit for text updates is 700 characters. If the message you are sending is longer than that, then it would explain why it gets split into multiple ones.
Regards, Bobby