I am trying to send some payment receipts via Whastapp Web, as I have done via e-mail, but I can not specify the name of the file to send and press 'Enter' in the Windows common control dialog. I know that it is not possible to do it directly with Selenium and I've tried with win32gui, without success.
This is the code I've been using to test:
import win32gui
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
send_to = 'John Smith'
attach_name = "GyG Recibo_00741.pdf"
# Lets use Chrome as web browser
web_driver = webdriver.Chrome('ChromeDriver')
# Open WhatsApp Web
web_driver.get('http://web.whatsapp.com')
web_driver.implicitly_wait(100) # seconds
# Find destinatary
new_chat = web_driver.find_element_by_id('input-chatlist-search')
new_chat.send_keys(send_to, Keys.ENTER)
# Press Attach button
button = web_driver.find_elements_by_xpath('//*[@id=\"main\"]/header/div[3]/div/div[2]/div/span')
button[0].click()
# Press Document button
inp_xpath = '//*[@id=\"main\"]/header/div[3]/div/div[2]/span/div/div/ul/li[3]/button'
button = web_driver.find_elements_by_xpath(inp_xpath)
button[0].click()
# Loop until Open dialog is displayed (my Windows version is in Spanish)
hdlg = 0
while hdlg == 0:
hdlg = win32gui.FindWindow(None, "Abrir")
# Set filename and press Enter
hwnd = 0x000047C # ControlID (as reported by Spy++)
filename = attach_name
ent = "{ENTER}"
win32gui.SetDlgItemText(hdlg, hwnd, filename)
win32gui.SetDlgItemText(hdlg, hwnd, ent)