Skip to content

[BUG] wait_for_function() ignores polling parameter #1584

@johnhawkinson

Description

@johnhawkinson

Context:

  • Playwright Version: 1.27.0
  • Operating System: Mac
  • Python version: 3.8
  • Browser: All

Describe the bug

Playwright's python bindings appear to ignore the polling parameter (or more properly, fail to pass it properly to the playwright driver). At least, assuming I am properly passing it, which I think I am, although I have not found examples of its use, so perhaps I'm missing something obvious.

For instance, this code should produce an error, because polling must be either a floating point number (milliseconds) or the string raf:

from playwright.sync_api import sync_playwright
import time

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()
    page.goto("http://playwright.dev")
    jsh = page.wait_for_function("""
function() { 
  console.log("poll", Date.now());
  return document.querySelector('foobar');
}
        """, polling="bogus")
    print(page.title())
    browser.close()

Compare with Javascript bindings

For instance, the equivalent Node.js script gives the proper error:

const playwright = require('playwright');

(async () => {
  // Setup
  const browser = await playwright.chromium.launch({headless: false});
  const page = await browser.newPage();

  await page.goto('https://playwright.dev');
  const watchDog = page.waitForFunction(() => { 
    console.log("poll", Date.now());
    return document.querySelector('foobar');
  }, null, { polling: "bogus" } );

})()

which properly returns

jhawk@lrr wff3b_test % node wff3b.js     
/Users/jhawk/src/wff3b_test/node_modules/playwright-core/lib/utils/index.js:100
  if (!value) throw new Error(message || 'Assertion error');
                    ^

Error: Unknown polling option: bogus
    at assert (/Users/jhawk/src/wff3b_test/node_modules/playwright-core/lib/utils/index.js:100:21)
    at Frame.waitForFunction (/Users/jhawk/src/wff3b_test/node_modules/playwright-core/lib/client/frame.js:582:64)
    at Page.waitForFunction (/Users/jhawk/src/wff3b_test/node_modules/playwright-core/lib/client/page.js:760:28)
    at /Users/jhawk/src/wff3b_test/wff3b.js:9:25

Node.js v18.10.0

An alternative example

For a more useful example, consider this:

from playwright.sync_api import sync_playwright
import time

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()
    page.goto("http://playwright.dev")
    jsh = page.wait_for_function("""
function() { 
  console.log("poll", Date.now());
  return document.querySelector('foobar');
}
        """, polling=1000.1)
    print(page.title())
    browser.close()

Which should only print to the console once per second (well, every 1000.1 milliseconds).
But if you open the Javascript Console in Chromium's Developer Tools, you will see a continuous stream of timestamped logs ("poll").

Again, the Node bindings work fine:

const playwright = require('playwright');

(async () => {
  // Setup
  const browser = await playwright.chromium.launch({headless: false});
  const page = await browser.newPage();

  await page.goto('https://playwright.dev');
  const watchDog = page.waitForFunction(() => { 
    console.log("poll", Date.now());
    return document.querySelector('foobar');
  }, null, { polling: 1000.1 } );

})()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions