microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.74k stars 3.58k forks source link

[Bug]: locator.waitfor in frameLocator not working #29405

Closed fancy45daddy closed 7 months ago

fancy45daddy commented 7 months ago

Version

1.38.0

Steps to reproduce

I have a website https://kiiky.com/ but the iframe load is a bit slow, so I want to waitfor an element exist in iframe and then do some stuff so I write the following code

import * as playwright from 'playwright-chromium'
import path from 'path'
import {promises as fs} from 'fs'
import os from 'os'
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'tmp')) 
const context = await playwright.chromium.launchPersistentContext(tmp, {channel:'chrome', args:['--disable-blink-features=AutomationControlled', '--start-maximized'], headless:false, viewport:null})
context.setDefaultTimeout(0)
const page = await context.newPage()
await page.goto('https://kiiky.com'), {waitUntil:'domcontentloaded'})
await page.mouse.wheel(0, await page.evaluateHandle(() => globalThis.document.documentElement.clientHeight).then(_ => _.jsonValue()))
await page.mouse.wheel(0, -await page.evaluateHandle(() => globalThis.document.documentElement.clientHeight).then(_ => _.jsonValue()))
await page.frameLocator('iframe:where([id^=google_ads_iframe_], [src^="https://googleads.g.doubleclick.net"])').first().locator('img').first().waitFor()) //wait for img exist in the first iframe
//do some other stuff

But the program hang in

await page.frameLocator('iframe:where([id^=google_ads_iframe_], [src^="https://googleads.g.doubleclick.net"])').first().locator('img').first().waitFor())

But I can see from the chrome element the img element already exist but the waitFor still hang

Expected behavior

waitfor() stop and exec the next step

Actual behavior

waitfor() hang

Additional context

No response

Environment

os: ubuntu 22.04
node: v21.2.0
npm: 10.2.3
playwright: 1.38.0
dgozman commented 7 months ago

@fancy45daddy Thank you for the issue.

I have run the repro script, and it indeed hangs on the waitFor() call. However, when manually checking in DevTools, I can find the requested iframe, but there is no <img> inside that iframe.

I believe that Playwright is unable to find the img and correctly hangs. Do you see something else?

dgozman commented 7 months ago

Closing as per above. If you still encounter problems, please file a new issue with a repro and link to this one.