'"pywhatskit" on python not sending message

Using the module pywhatkit you can send messages on WhatsApp,

I used the script:

import pywhatkit as w

w.sendwhatmsg("xxxxxxxx", " this is a generated msg",9,26)

x is the number

The problem is, all it does is load the message in WhatsApp's textbox, it does not send. Am I missing something?



Solution 1:[1]

I just had the same issue, and I uninstalled and installed again pywhatkit with the following commands:

pip uninstall pywhatkit
pip install pywhatkit

I know this question is old, hope it will help someone with the same problem

Solution 2:[2]

you must increase the waiting time to more than or equal to 30 seconds, it happens generally due to slow internet. write it like this:

import pywhatkit as py
py.sendwhatmsg("+91xxxxxxxxxx", "hello", 13, 12, 32)

Solution 3:[3]

import pywhatkit as w
import time
import pyautogui
import keyboard as k
w.sendwhatmsg("your number", 'hi', 8, 38)
pyautogui.click(1050, 950)
time.sleep(2)
k.press_and_release('enter')

by pyautogui.click you can adjust cursor to message box and then it will click on it and after that with keyboard you can click enter as simple as that

Solution 4:[4]

This seems to be a bug in Pywhatkit: https://github.com/Ankit404butfound/PyWhatKit/issues/20

Solution 5:[5]

the module currently only supports 1 screen, if you are using multiple screens and the new whatsapp web is currently opening on a separate window from where your code is running is going to give you that error. It is a known issue therefore if you are going to use more than one screen (who isn't) ensure your editor of choice (ie: google chrome and visual studio) are on the same screen.

Solution 6:[6]

After debugging sendwhatmsg function is doing the following things

  1. opening your default browser using this query web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
  2. clicking here pg.click(core.WIDTH / 2, core.HEIGHT / 2)
  3. and pressing enter pg.press("enter")

The main problem is that this 2 variables core.WIDTH and core.HEIGHT gives you the resolution of your screen, not the resolution of the tab just opened in the browser. So if the browser tab its not maximized you might end up clicking somewhere else. So please make sure that your browser its maximized when opening.

Solution 7:[7]

The problem is that the window in which pywhatkit opens Whatsapp Web is not selected. When it opens Whatsapp Web, waits for a few seconds and clicks 'enter', the 'enter' is not processed by the browser window. Add the following code to your program:

# Import Libraries
import pywhatkit
import pyautogui
from tkinter import *

win = Tk() # Some Tkinter stuff
screen_width = win.winfo_screenwidth() # Gets the resolution (width) of your monitor
screen_height= win.winfo_screenheight() # Gets the resolution (height) of your monitor

print(screen_width, screen_height) # prints your monitor's resolution

pywhatkit.sendwhatmsg("+91xxxxxxxxxx", "Enter Message", 0, 0) # Sends the message
pyautogui.moveTo(screen_width * 0.694, screen_height* 0.964) # Moves the cursor the the message bar in Whatsapp
pyautogui.click() # Clicks the bar
pyautogui.press('enter') # Sends the message

No matter what screen you are using, pyautogui will always send your message except if Whatsapp updates its UI. In case this happens, then check where the message bar is located through pyautogui and whatever values you get, divide it by your screen's resolution. This way, it will work on any monitor.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide Antipa
Solution 2 Monodeep Saha
Solution 3 Dharman
Solution 4 AKX
Solution 5 Rob Palomo
Solution 6 Jonathan Figueroa
Solution 7 Soham Grover