Comments (5)
I solved this sh!t, the problem is that you are running it on one monitor and the browser is opening on another, it ends up losing focus. It basically runs the code on the same monitor where you use the browser. This is all pyauto's fault...
from pywhatkit.
The same thing is happening to me, with Macos Sonoma. Did you find any solution?
from pywhatkit.
Just as a contribution to explain how this works, basically this is the code for almost all functions, but I will use the sendwhatmsg_instantly()
as example:
def sendwhatmsg_instantly(
phone_no: str,
message: str,
wait_time: int = 15,
tab_close: bool = False,
close_time: int = 3,
) -> None:
"""Send WhatsApp Message Instantly"""
if not core.check_number(number=phone_no):
raise exceptions.CountryCodeException("Country Code Missing in Phone Number!")
web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
time.sleep(4)
pg.click(core.WIDTH / 2, core.HEIGHT / 2)
time.sleep(wait_time - 4)
pg.press("enter")
log.log_message(_time=time.localtime(), receiver=phone_no, message=message)
if tab_close:
core.close_tab(wait_time=close_time)
This is on the whats.py module, the thing works as follows:
- Opens the window like a wa.me.
- waits for 4 seconds.
- clicks on the center of the screen.
- waits for the time you added to wait, less 4 seconds, to balance the time it already waited by default.
- Presses enter
- Logs stuff
- closes tab if you asked to.
The main issue as @GuilhermeTiede said, is pyautogui's fault, (here as pg
), what this code does is mimic a user sending a message and later closing the tab, clicking on the center of the screen to "toggle" the use of the chat (thinking you will have it on Fullscreen), so if it is not precise, like having 2 screens, having a little or cornered window, or load one more second later than the 4 it uses to estimate the load time, it just does what the Whatsapp API does, but everything else goes off-rails.
An easy way to solve the majority of the issues regarding not sending the message, it's adding more wait time (in case you detect it takes more than 4 seconds to load the webapp) and preparing everything so it goes as expected, as having the browser open up in the main screen in case you have 2 or more screens.
The real solution would be throwing away pyautogui or at least the method this library is using and use a more sophisticated method to open up the window and make Python wait until the window loads and send the message wherever your window is.
P.D. First time contributing on an issue in GH, I hope I'm doing it right.
from pywhatkit.
Related Issues (20)
- can we add participant to the group from contact ?
- pywhatkit.sendwhatmsg HOT 2
- The pywhatkit.sendwhatmsg_instantly() method sometimes sends the messages and sometimes wont. HOT 2
- text_to_handwriting() function is not working in pywhatkit HOT 3
- Issues with running PyWhatKit on RPi (Ubuntu)
- Send message to contact list in csv file
- No module named pywhatkit found after installing HOT 2
- Getting error: " AttributeError: module 'pywhatkit' has no attribute 'sendimg_or_video_immediately' " HOT 2
- CFURLGetFSRef was passed a URL which has no scheme (the URL will not work with other CFURL routines) HOT 1
- method not send message need to type to send in prompt HOT 5
- Pywhat in .exe
- informacion de las excepciones
- pywhatkit.core.exceptions.InternetException: Error while connecting to the Internet. Make sure you are connected to the Internet! HOT 1
- Add a feature to send message to whatsapp channel
- Feature to send message to whatsapp channel
- Sending pdf's to whatsapp groups HOT 3
- Message Sending not working HOT 2
- pywhatkit
- [QUESTION] Issue KeyError: DISPLAY HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywhatkit.