Question Details

No question body available.

Tags

python selenium-webdriver automation whatsapp

Answers (3)

January 7, 2026 Score: 1 Rep: 194,839 Quality: Medium Completeness: 60%

Once you open WhatsApp Web and enter the chat and try to locate the element with CSSSELECTOR:

input[type='file']

The default element is identified which is:


Though an element with style="display: none; but accepts only image/*. Hence when you pass a PDF file you see the error:

1 file you tried to add is not supported.

Solution

You need to send the PDF file to the following element:


and this element would accept all the supported files including PDF.

Working code block:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expectedconditions as EC

driver.get(url='https://web.whatsapp.com/')

... code to open WhatsApp Web and enter the chat ...

WebDriverWait(driver, 20).until(EC.elementtobeclickable((By.XPATH, "//div[@aria-label='Search input textbox']/p"))).sendkeys("Paullyno") WebDriverWait(driver, 20).until(EC.elementtobeclickable((By.XPATH, "//span[contains(., 'Chats')]//following::span[starts-with(@title, 'Paullyno')]"))).click() WebDriverWait(driver, 20).until(EC.elementtobeclickable((By.XPATH, "//span[@data-icon='plus-rounded']"))).click() WebDriverWait(driver, 20).until(EC.elementtobeclickable((By.XPATH, "//div[@role='application']/ul//span[text()='Document']"))).click() attach = driver.findelement(By.CSSSELECTOR, "input[type='file'][multiple]") attach.sendkeys(os.path.abspath(default/archive.pdf)) WebDriverWait(driver, 20).until(EC.elementtobe_clickable((By.XPATH, "//div[@aria-label='Send']/span[@data-icon='wds-ic-send-filled']"))).click()
January 3, 2026 Score: 0 Rep: 1,442 Quality: Low Completeness: 30%

Click first paperclip first

clip = wait.until(EC.elementtobeclickable((By.CSSSELECTOR, "span[data-icon='clip']"))) clip.click()
January 26, 2026 Score: 0 Rep: 1 Quality: Low Completeness: 60%

I apologize if there are any errors in the English; I'm using Google Translate. For some reason, Chrome only loads the input now when the attach button is clicked. I tried every way to make it attach to the correct input, but it always went to the same incorrect one. So what worked for me was the following: I got to a point where I was out of patience and trying everything I could with Gemini to solve it. There's definitely room for improvement in this part of the code, but I believe the logic for correction is the same. I didn't write any of this code, so I don't recommend copying and pasting. I kindly ask that if anyone has a cleaner solution without using AI, please reply here.

time.sleep(2) 
        driver.findelement(By.CSSSELECTOR, "span[data-icon='plus-rounded']").click()
        time.sleep(1) 

try: driver.findelement(By.XPATH, "//*[contains(text(), 'Document')]").click() except: driver.findelements(By.CSSSELECTOR, "ul > li")[0].click() time.sleep(1)

inputs = driver.find
elements(By.TAGNAME, "input") inputfinal = None for inp in inputs: try: accept = inp.getattribute("accept") if not accept or "image" not in accept: inputfinal = inp break except: continue

if inputfinal: inputfinal.sendkeys("\n".join(arquivos))

try: driver.execute
script("arguments[0].dispatchEvent(new Event('change', { bubbles: true }));", inputfinal) except StaleElementReferenceException: pass

print(f" Arquivos carregados. Tentando clicar em enviar...")

sucesso
envio = False tempolimite = time.time() + 30 while time.time() < tempolimite: try:

btn = driver.findelement(By.XPATH, '//span[@data-icon="wds-ic-send-filled"]') btn.click() sucessoenvio = True break except (StaleElementReferenceException, NoSuchElementException): time.sleep(0.5)