---
id: "c1331153-ea43-4887-9fd5-5f951555b2ff"
name: "Thread Opening by td[role]"
micro_summary: "Opens Gmail threads by scrolling the matching td[role] row into view and clicking its subject-side coordinates with CDP."
status: "resolved"
see_also: []
scope: "How to open a Gmail thread by clicking its row in the inbox. Uses td[role] elements, scrollIntoView, and CDP mouse events."
warnings: "Click the right side of td[role] rows (subject area), not the left (sender column). Left-side clicks may not open threads."
---
## How It Works
Gmail inbox threads are rendered as `
` elements. Clicking the right side (subject area) opens the thread view.
```python
# Find and open a thread by keyword in its text
result = js("""
(() => {
const rows = document.querySelectorAll('td[role]');
for (const row of rows) {
if (row.innerText.includes('target keyword')) {
row.scrollIntoView({behavior: "instant", block: "center"});
const rect = row.getBoundingClientRect();
return JSON.stringify({x: Math.round(rect.right - 80), y: Math.round(rect.top + rect.height / 2)});
}
}
return 'null';
})()
""")
pos = json.loads(result)
time.sleep(0.5) # wait for scroll
cdp("Input.dispatchMouseEvent", type="mousePressed", x=pos["x"], y=pos["y"], button="left", clickCount=1, session_id=sid)
time.sleep(0.1)
cdp("Input.dispatchMouseEvent", type="mouseReleased", x=pos["x"], y=pos["y"], button="left", clickCount=1, session_id=sid)
time.sleep(3) # wait for thread to load
text = extract_text() # full thread content
```
## Key Details
- Click the **right side** of the row (`rect.right - 80`), not the left. Left side clicks sometimes don't open threads.
- Must use `scrollIntoView` first — rows below viewport won't respond to clicks even with CDP.
- After opening, `extract_text()` returns the full thread including all messages.
- Verify you opened successfully: if "of 84" is in the text, you're still on the inbox listing. |