-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_attachment.py
More file actions
89 lines (73 loc) · 3.63 KB
/
test_attachment.py
File metadata and controls
89 lines (73 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
Test script to check attachment button selectors in WhatsApp Web
"""
import asyncio
from playwright.async_api import async_playwright
async def test_attachment_selectors():
"""Test attachment button selectors"""
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
page.set_default_timeout(0) # No timeout
print("🌐 Navigating to WhatsApp Web...")
await page.goto("https://web.whatsapp.com")
print("⏳ Please scan QR code and open any chat...")
print("⏳ Waiting 30 seconds for you to manually open a chat...")
await asyncio.sleep(30)
print("🔍 Testing attachment button selectors...")
# Test attachment button selectors
attachment_selectors = [
'div[title="Attach"]',
'span[data-testid="clip"]',
'button[aria-label="Attach"]',
'div[aria-label="Attach"]',
'span[data-icon="attach-menu-plus"]',
'button[data-testid="attach-menu-plus"]',
'div[data-testid="attach-menu-plus"]',
'div[role="button"][title*="ttach"]',
'button[title*="ttach"]',
'span[aria-label*="ttach"]',
'svg[viewBox*="24"]', # Generic attachment icon
'button[aria-label*="menu"]'
]
found_selectors = []
for selector in attachment_selectors:
try:
elements = await page.query_selector_all(selector)
if elements:
print(f"✅ {selector}: Found {len(elements)} elements")
found_selectors.append(selector)
# Get more details about the first element
element = elements[0]
tag_name = await element.evaluate('el => el.tagName')
classes = await element.evaluate('el => el.className')
title = await element.evaluate('el => el.title || el.getAttribute("aria-label") || "no title"')
print(f" <{tag_name}> classes='{classes}' title='{title}'")
else:
print(f"❌ {selector}: No elements found")
except Exception as e:
print(f"❌ {selector}: Error - {e}")
if found_selectors:
print(f"\n🎯 Found {len(found_selectors)} working selectors!")
print("Testing the first working selector...")
try:
first_selector = found_selectors[0]
button = await page.query_selector(first_selector)
if button:
print(f"🖱️ Clicking attachment button with selector: {first_selector}")
await button.click()
await asyncio.sleep(2)
print("✅ Attachment button clicked successfully!")
# Look for file input after clicking
file_inputs = await page.query_selector_all('input[type="file"]')
print(f"📁 Found {len(file_inputs)} file input elements after clicking")
except Exception as e:
print(f"❌ Error clicking attachment button: {e}")
else:
print("❌ No working attachment selectors found")
print("\n⏳ Keeping browser open for 10 more seconds...")
await asyncio.sleep(10)
await browser.close()
if __name__ == "__main__":
asyncio.run(test_attachment_selectors())