Skip to content

[FEATURE] Playwright does not support dynamic browser name #731

@kumaraditya303

Description

@kumaraditya303

Playwright in typescript supports accessing the browser name with its string name like :

const playwright = require('playwright');

(async () => {
  for (const browserType of ['chromium', 'firefox', 'webkit']) {
    const browser = await playwright[browserType].launch();
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('http://whatsmyuseragent.org/');
    await page.screenshot({ path: `example-${browserType}.png` });
    await browser.close();
  }
})();

Whereas in python, it will errors as the playwright object is not subscriptable

TypeError: 'Playwright' object is not subscriptable 

Playwright should make the playwright subscriptable to be able to dynamically launch browser from string

TBD API:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    for browser_type in ["chromium", "firefox", "webkit"]:
        browser = p[browser_type].launch()
        page = browser.new_page()
        page.goto("http://whatsmyuseragent.org/")
        page.screenshot(path=f"example-{browser_type.name}.png")
        browser.close()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions