Hi - I have a streamlit app which mimics a weekly report. I need to take snapshot of that UI everyweek per director. we have 3 filters for that UI, its period/week and director. so per director i need to take snapshot.

tried using playwright connected headless browser(chrome)
code used:
async def take_screenshots():

async with async_playwright() as p:

    browser = await p.chromium.launch(headless=True, args=\["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"\])

    page = await browser.new_page()

print(“opening app…”)
await page.goto(APP_URL,timeout = 60000)

# :white_check_mark: Wait for STABLE page indicator

#await page.get_by_text(“Grocery Revenue Report”).wait_for(timeout=120000)

for director in directors:

try:

print(f"Processing: {director}")

# Click dropdown and select director

            dropdowns = page.locator("div\[data-baseweb='select'\]")

            director_dropdown = dropdowns.nth(3)

await director_dropdown.wait_for(state=“visible”, timeout=60000)

await director_dropdown.click()

# Select director

            option = page.get_by_text(director, exact=True)

await option.wait_for(state=“visible”, timeout=60000)

await option.click()

# Wait for Streamlit to rerender

await page.wait_for_timeout(5000)

#await page.click(f"text=‘{director}’")

# Wait for Streamlit rerun

#await page.wait_for_timeout(3000)
safe_name = clean_name(director)

            file_path = os.path.join(OUTPUT_DIR, f"Director {safe_name}.png")

await page.screenshot(path=file_path, full_page=True)

print(f"Saved: {file_path}“)
except Exception as e:
print(f"Error for {director}: {e}”)
await browser.close()
ERR{Error for Director1: Locator.wait_for: Timeout 60000ms exceeded.
Call log:

  • waiting for locator(“div[data-baseweb=‘select’]”).nth(3) to be visible}

Hey there, thanks for sharing your code and the detailed error! :tada: You’re definitely not alone—many folks run into Playwright timeouts with Streamlit apps, especially when waiting for elements to become visible after a rerun. The error Locator.wait_for: Timeout 60000ms exceeded means Playwright couldn’t find the dropdown in time, likely because Streamlit was still rerendering or the selector didn’t match.

Key points and best practices:

  • Streamlit reruns the script on every interaction, so UI elements (like dropdowns) may not be immediately available after a click.
  • Hardcoded timeouts (wait_for_timeout) are unreliable for Streamlit, especially with charts or heavy rerenders.
  • Instead, use Playwright’s built-in waiting mechanisms (like wait_for_selector or expect(locator).to_be_visible()) and ensure your selectors are correct and unique.
  • For flaky elements, consider waiting for a stable page indicator or a unique element that only appears after rerender.

Example fix:

# Wait for the dropdown to be attached and visible
await page.wait_for_selector("div[data-baseweb='select']", state="visible", timeout=60000)
dropdowns = page.locator("div[data-baseweb='select']")
director_dropdown = dropdowns.nth(3)
await director_dropdown.click()

If the dropdown index changes after rerun, try using a more specific selector or wait for a unique label/text near the dropdown.

For more robust solutions and community tips, see this forum thread and another on Playwright/Streamlit integration.

Sources: