Method: Playwright::Frame#wait_for_selector
- Defined in:
- lib/playwright_api/frame.rb
#wait_for_selector(selector, state: nil, strict: nil, timeout: nil) ⇒ Object
Returns when element specified by selector satisfies ‘state` option. Returns `null` if waiting for `hidden` or `detached`.
NOTE: Playwright automatically waits for element to be ready before performing an action. Using ‘Locator` objects and web-first assertions make the code wait-for-selector-free.
Wait for the ‘selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the selector doesn’t satisfy the condition for the ‘timeout` milliseconds, the function will throw.
Usage
This method works across navigations:
“‘python sync from playwright.sync_api import sync_playwright
def run(playwright):
chromium = playwright.chromium
browser = chromium.launch()
page = browser.new_page()
for current_url in ["https://google.com", "https://bbc.com"]:
page.goto(current_url, wait_until="domcontentloaded")
element = page.main_frame.wait_for_selector("img")
print("Loaded image: " + str(element.get_attribute("src")))
browser.close()
with sync_playwright() as playwright:
run(playwright)
“‘
1014 1015 1016 |
# File 'lib/playwright_api/frame.rb', line 1014 def wait_for_selector(selector, state: nil, strict: nil, timeout: nil) wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout))) end |