sidechat_manager: Use data-testid for sidebar button\n\nReliable selector hatch-chat-switcher-trigger instead of\nflaky text matching.
This commit is contained in:
+11
-7
@@ -31,6 +31,8 @@ def ensure_sidebar(ws, max_retries=3):
|
||||
"""
|
||||
Ensure the sidebar is open. Returns True if open, False otherwise.
|
||||
Retries with backoff if the open button isn't found immediately.
|
||||
Uses data-testid="hatch-chat-switcher-trigger" (reliable selector).
|
||||
Fixed 2026-10-04: was using text matching which was flaky.
|
||||
"""
|
||||
for attempt in range(max_retries):
|
||||
# Check if sidebar is already open (Side chats text visible)
|
||||
@@ -40,13 +42,15 @@ def ensure_sidebar(ws, max_retries=3):
|
||||
if is_open:
|
||||
return True
|
||||
|
||||
# Try to open it
|
||||
_ev(ws, """(() => {
|
||||
const btn = [...document.querySelectorAll('button')].find(b =>
|
||||
(b.textContent||'').includes('Open chat and side chats')
|
||||
);
|
||||
if (btn) btn.click();
|
||||
return !!btn;
|
||||
# Try to open it via data-testid (reliable)
|
||||
clicked = _ev(ws, """(() => {
|
||||
const btn = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]');
|
||||
if (btn) { btn.click(); return true; }
|
||||
// Fallback: text matching
|
||||
const fb = [...document.querySelectorAll('button')].find(b =>
|
||||
(b.textContent||'').includes('Open chat and side chats'));
|
||||
if (fb) { fb.click(); return true; }
|
||||
return false;
|
||||
})()""")
|
||||
time.sleep(2 * (attempt + 1)) # Exponential backoff: 2s, 4s, 6s
|
||||
|
||||
|
||||
Reference in New Issue
Block a user