class Playwright::Selectors
information.
Selectors can be used to install custom selector engines. See [extensibility](../extensibility.md) for more
def event_emitter_proxy
def event_emitter_proxy _emitter_proxy ||= EventEmitterProxy.new(self, @impl)
def off(event, callback)
-- inherited from EventEmitter --
def off(event, callback) event_emitter_proxy.off(event, callback) end
def on(event, callback)
-- inherited from EventEmitter --
def on(event, callback) event_emitter_proxy.on(event, callback) end
def once(event, callback)
-- inherited from EventEmitter --
def once(event, callback) event_emitter_proxy.once(event, callback) end
def register(name, script: nil, contentScript: nil, path: nil)
run(playwright)
with sync_playwright() as playwright:
browser.close()
print(button_count)
button_count = page.locator('tag=button').count()
# Can use it in any methods supporting selectors.
page.locator('tag=div').get_by_text('Click me').click()
# Combine it with built-in locators.
button = page.locator('tag=button')
# Use the selector prefixed with its name.
page.set_content('')
page = browser.new_page()
browser = playwright.chromium.launch()
playwright.selectors.register("tag", tag_selector)
# Register the engine. Selectors will be prefixed with "tag=".
}"""
}
return Array.from(root.querySelectorAll(selector));
queryAll(root, selector) {
// Returns all elements matching given selector in the root's subtree.
},
return root.querySelector(selector);
query(root, selector) {
// Returns the first element matching given selector in the root's subtree.
{
tag_selector = """
def run(playwright: Playwright):
from playwright.sync_api import sync_playwright, Playwright
```python sync
An example of registering selector engine that queries elements based on a tag name:
**Usage**
Selectors must be registered before creating the page.
def register(name, script: nil, contentScript: nil, path: nil) wrap_impl(@impl.register(unwrap_impl(name), script: unwrap_impl(script), contentScript: unwrap_impl(contentScript), path: unwrap_impl(path))) end
def set_test_id_attribute(attributeName)
def set_test_id_attribute(attributeName) raise NotImplementedError.new('set_test_id_attribute is not implemented yet.') end
def text_id_attribute=(attribute_name)
def text_id_attribute=(attribute_name) wrap_impl(@impl.text_id_attribute=(unwrap_impl(attribute_name))) end