Method: Playwright::Frame#wait_for_function

Defined in:
lib/playwright_api/frame.rb

#wait_for_function(expression, arg: nil, polling: nil, timeout: nil) ⇒ Object

Returns when the expression returns a truthy value, returns that value.

Usage

The [method: Frame.waitForFunction] can be used to observe viewport size change:

from playwright.sync_api import sync_playwright, Playwright

def run(playwright: Playwright):
    webkit = playwright.webkit
    browser = webkit.launch()
    page = browser.new_page()
    page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
    page.main_frame.wait_for_function("() => window.x > 0")
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

To pass an argument to the predicate of frame.waitForFunction function:

selector = ".foo"
frame.wait_for_function("selector => !!document.querySelector(selector)", selector)


937
938
939
# File 'lib/playwright_api/frame.rb', line 937

def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
  wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
end