class Playwright::Playwright
Playwright
module provides a method to launch a browser instance. The following is a typical example of using Playwright
to drive automation:
“`python sync from playwright.sync_api import sync_playwright
def run(playwright):
chromium = playwright.chromium # or "firefox" or "webkit". browser = chromium.launch() page = browser.new_page() page.goto("http://example.com") # other actions... browser.close()
with sync_playwright() as playwright:
run(playwright)
“`
Public Instance Methods
@nodoc
# File lib/playwright_api/playwright.rb, line 85 def android wrap_impl(@impl.android) end
This object can be used to launch or connect to Chromium, returning instances of `Browser`.
# File lib/playwright_api/playwright.rb, line 22 def chromium # property wrap_impl(@impl.chromium) end
Returns a dictionary of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`].
“`python sync from playwright.sync_api import sync_playwright
def run(playwright):
webkit = playwright.webkit iphone = playwright.devices["iPhone 6"] browser = webkit.launch() context = browser.new_context(**iphone) page = context.new_page() page.goto("http://example.com") # other actions... browser.close()
with sync_playwright() as playwright:
run(playwright)
“`
# File lib/playwright_api/playwright.rb, line 44 def devices # property wrap_impl(@impl.devices) end
@nodoc
# File lib/playwright_api/playwright.rb, line 90 def electron wrap_impl(@impl.electron) end
This object can be used to launch or connect to Firefox, returning instances of `Browser`.
# File lib/playwright_api/playwright.rb, line 49 def firefox # property wrap_impl(@impl.firefox) end
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/playwright.rb, line 108 def off(event, callback) event_emitter_proxy.off(event, callback) end
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/playwright.rb, line 102 def on(event, callback) event_emitter_proxy.on(event, callback) end
– inherited from EventEmitter
– @nodoc
# File lib/playwright_api/playwright.rb, line 96 def once(event, callback) event_emitter_proxy.once(event, callback) end
Selectors
can be used to install custom selector engines. See [Working with selectors](./selectors.md) for more information.
# File lib/playwright_api/playwright.rb, line 55 def selectors # property wrap_impl(@impl.selectors) end
Terminates this instance of Playwright
in case it was created bypassing the Python context manager. This is useful in REPL applications.
“`py >>> from playwright.sync_api import sync_playwright
>>> playwright = sync_playwright().start()
>>> browser = playwright.chromium.launch() >>> page = browser.new_page() >>> page.goto(“whatsmyuseragent.org/”) >>> page.screenshot(path=“example.png”) >>> browser.close()
>>> playwright.stop() “`
# File lib/playwright_api/playwright.rb, line 80 def stop raise NotImplementedError.new('stop is not implemented yet.') end
This object can be used to launch or connect to WebKit, returning instances of `Browser`.
# File lib/playwright_api/playwright.rb, line 60 def webkit # property wrap_impl(@impl.webkit) end
Private Instance Methods
# File lib/playwright_api/playwright.rb, line 112 def event_emitter_proxy @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl) end