Problems in the automation of sending messages on Whatsapp through the Python Selenium library

Asked

Viewed 668 times

0

I’m with an automatic messaging project via Whatsapp that consists of sending messages provided with special characters (emojis and other symbols) saved in files . txt, however, whenever I use the following code:

Trava = open('c:/Users/Marco Neto/Desktop/ataquepalhaco.txt', encoding='utf-8').read()

(...)

self.driver = webdriver.Chrome(executable_path=r'./chromedriver.exe')

He makes the following mistake:

selenium.common.exceptions.WebDriverException: Message: unknown error: ChromeDriver only supports characters in the BMP

I have already searched for, however, the only solution I found regarding this problem was to change webdriver and, instead of using Chrome, use Firefox. I tried through the following code but unfortunately also went wrong:

self.driver = webdriver.Firefox(executable_path=r'./geckodriver.exe')

Code error above:

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

In short, I would like an alternative or resolution to the codes so I can insert special characters in a file. txt and send it by Whatsapp by Lenium.

  • It is very difficult to reproduce the error with the information you have passed on. It is no longer easy for you to use key strings in your txt and have Selenium search for the item in the emoticons tab?

2 answers

0

Unable to send emojis using Chrome at the moment due to a bug. You must use firefox.

Regarding the error on Firefox startup, there are several possibilities:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
browser = webdriver.Firefox(capabilities=cap, executable_path="C:\\path\\to\\geckodriver.exe")
browser.get('http://google.com/')
browser.quit()

In addition, the parameter executable_path of webdriver.Firefox expects a complete path, but you passed a relative. Try replacing './geckodriver.exe' with the full address of where this executable is.

0

I have already had in hand a project of this characteristic.

I used the Whatsapp api to automate text and emoji submissions, uploading photos and videos was very loooongo the coding time but it worked well.

To send a message using the pc, you initially have to go through the QR Code. To circumvent this mechanism using mv.

Unfortunately in your doubt you did not pass the code,only a part but I will show a simple example of my github.

When started will ask for authentication by mobile, will be redirected to the message page and send text to each number indicated.

from selenium.webdriver.common.by import By
from selenium import webdriver
import schedule
 
class Whatsapp:

    def driver(self):
        driver = webdriver.Chrome('/home/..') # driver google
        return driver

    def mensagem_whatsapp(self, mensagem, numeros_celulares):

       driver_extensao = Whatsapp().driver()
        driver_extensao.get(f"https://web.whatsapp.com/send?phone={numeros_celulares}&source=&data=#") # api web
        print("Autentificaçao[Web, Desktop] ")
        driver_extensao.find_element(By.XPATH,'//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
        campo = driver_extensao.find_element(By.XPATH, '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
        print("Envio : ", campo.send_keys(mensagem))
        campo.send_keys("\n")


def robo():
    pessoas = [0010101] # lista de numeros
    mensagemE = "Ola, estao" # frase, pode interagir com teu txt

    enviarAgora = Whatsapp()
    for possomandar in pessoas:
        enviarAgora.mensagem_whatsapp(mensagem=mensagemE, numeros_celulares=pessoas)

#only start with main with robot function

Whatsapp source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.