DEV Community

markbusking
markbusking

Posted on

How to Automate WhatsApp with Python in 2026 (No Selenium, No BS)

How to Automate WhatsApp with Python in 2026

Every WhatsApp automation tutorial still recommends selenium with fragile XPath selectors that break every week. There's a better way.

Why Playwright + whatsplay?

Playwright is faster, more reliable, and whatsplay wraps the WhatsApp Web DOM with stable selectors (attribute-based instead of minified class names).

What you'll build
A bot that monitors a price and sends an alert to your WhatsApp group.

Install
pip install whatsplay playwright
playwright install chromium

Step 1: Connect to WhatsApp
from whatsplay import Client

client = Client()
client.launch()
client.wait_for_login()

Step 2: Send a message
chat = client.get_chat("Mi Grupo")
chat.send_message("¡Hola! Esto es automático 🤖")

Step 3: Monitor + alert (real use case)
import httpx

def check_price():
r = httpx.get("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
return r.json()["bitcoin"]["usd"]

@client.on_message()
def handler(msg):
if msg.text and "precio" in msg.text.lower():
price = check_price()
chat.send_message(f"BTC está en ${price:,}")

Why this approach wins

  • Selectors don't break on WhatsApp updates
  • Works with QR login, persistent sessions
  • 34 tests covering message parsing, timestamps, voice messages

Full docs: github.com/markbus-ai/whatsplay (https://github.com/markbus-ai/whatsplay)
PyPI: pip install whatsplay

Top comments (0)