I’m using Playwright (Python) to automate a web-based Flux AI music video generator. The manual flow is simple:
Upload 1–5 photos
Upload an MP3
Enter a short motion prompt
Click “Generate”
The generation itself is asynchronous and can take 30–180+ seconds (depends on song length, model, queue). After clicking Generate, the page shows a loading state (progress spinner or similar), then replaces it with a video player + download button once it’s ready.I can handle the uploads and form submission fine, but I’m struggling with the “wait for completion” part.What I’ve already tried:
# 1. Fixed wait – works but wasteful
await page.wait_for_timeout(120_000)
# 2. Wait for visible element (flaky – element sometimes appears before video is actually ready)
await page.wait_for_selector('#download-btn', state='visible', timeout=180_000)
# 3. Simple polling
async def wait_for_video():
for _ in range(60): # ~3 min max
if await page.locator('.video-player').count() > 0 and await page.locator('.video-player video[src]').count() > 0:
return
await page.wait_for_timeout(3000)
raise TimeoutError
Problems I’m seeing:
The DOM is a React/Vue-style SPA → elements are reused, classes/IDs change between generations.
No obvious “job ID” or polling endpoint in the network tab (at least not obvious to me).
Network idle doesn’t help because the generation happens server-side.
What’s the most reliable way to detect that the video has finished generating and is ready to download? Preferred solutions:
Using page.wait_for_function() with a JavaScript condition (e.g. check video.duration or src)
Waiting for a specific network response (if there’s a final /result endpoint)
Any other pattern people use for AI tools like this (Runway, Pika, Kling, etc. have similar flows)