diff --git a/docs/src/extensibility.md b/docs/src/extensibility.md index 05065d95fc..cb5b9170ce 100644 --- a/docs/src/extensibility.md +++ b/docs/src/extensibility.md @@ -156,3 +156,29 @@ page.locator("tag=div").get_by_text("click me").click() # we can use it in any methods supporting selectors. button_count = page.locator("tag=button").count() ``` + +```csharp +// Register the engine. Selectors will be prefixed with "tag=". +// The script is evaluated in the page context. +await playwright.Selectors.Register("tag", new() { + Script = @" + // Must evaluate to a selector engine instance. + { + // Returns the first element matching given selector in the root's subtree. + query(root, selector) { + return root.querySelector(selector); + }, + + // Returns all elements matching given selector in the root's subtree. + queryAll(root, selector) { + return Array.from(root.querySelectorAll(selector)); + } + }" +}); + +// Now we can use "tag=" selectors. +await page.Locator("tag=button").ClickAsync(); + +// We can combine it with built-in locators. +await page.Locator("tag=div").GetByText("Click me").ClickAsync(); +```