Skip to content

Commit c7e851a

Browse files
committed
fix: reliably set Slack search sort order to 'Oldest'\n\nUses robust Playwright selectors to ensure export is chronological regardless of UI changes.
1 parent eefe316 commit c7e851a

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

slack_search_scraper.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,40 @@ async def navigate_to_search(page: Page, search_query: str):
9696

9797
console.print("[green]🔍 Waiting for results to load...[/green]")
9898
await page.wait_for_selector('.c-search_message__content', timeout=120000)
99-
99+
100+
# Ensure sort order is set to Oldest
101+
try:
102+
# Find the sort button by class and child span text
103+
sort_button = await page.query_selector('//button[contains(@class, "p-search_filter__trigger_button") and .//span[contains(text(), "Sort:")]]')
104+
if sort_button:
105+
sort_text = await sort_button.text_content()
106+
if sort_text and "Oldest" in sort_text:
107+
console.print("[cyan]Sort order already set to Oldest[/cyan]")
108+
else:
109+
await sort_button.click()
110+
await page.wait_for_timeout(500)
111+
# Find the dropdown option by visible text (robust to overlays/portals)
112+
# Playwright text selector: 'text=Oldest', but ensure it's visible
113+
try:
114+
await page.wait_for_selector('text=Oldest', timeout=3000, state='visible')
115+
oldest_options = await page.query_selector_all('text=Oldest')
116+
clicked = False
117+
for option in oldest_options:
118+
# Only click if visible
119+
if await option.is_visible():
120+
await option.click()
121+
console.print("[cyan]🔃 Set sort order to Oldest[/cyan]")
122+
clicked = True
123+
break
124+
if not clicked:
125+
console.print("[yellow]⚠️ Could not find a visible/clickable 'Oldest' sort option[/yellow]")
126+
except Exception as e:
127+
console.print(f"[yellow]⚠️ Error waiting for or clicking 'Oldest': {e}[/yellow]")
128+
else:
129+
console.print("[yellow]⚠️ Could not find sort button with 'Sort:' text[/yellow]")
130+
except Exception as sort_err:
131+
console.print(f"[yellow]⚠️ Error setting sort order: {sort_err}[/yellow]")
132+
100133
return True
101134

102135
except Exception as e:

0 commit comments

Comments
 (0)