'PyWhatKit Python open browser but sometimes not send the message

It just opens the browser and creates the message, but after the established wait time, it closes the tab and does not send the message.

Increasing wait time value works but it fails on some occasions.

Any suggestions?

def whatmsg(telef, notaw):
   hoy = datetime.datetime.now()
   hora_actual = datetime.datetime(hoy.year, hoy.month, hoy.day, hoy.hour, hoy.minute)
   hora_deseada = datetime.timedelta(minutes=2)
   salida = hora_actual + hora_deseada
   print(salida)
   kit.sendwhatmsg(telef, notaw, salida.hour, salida.minute, 35, True, 5)


Solution 1:[1]

try this..

import pywhatkit as w
import pyautogui
import keyboard as k

def whatmsg(telef, notaw)
  w.sendwhatmsg_instantly(telef, notaw)
  time.sleep(2)
  pyautogui.click()
  time.sleep(1)
  k.press_and_release('enter')

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 Aries Setiyawan