docs: add C# code snippet to extensibility.md (#27328)

Fixes #27160.
This commit is contained in:
Dmitry Gozman 2023-09-27 11:54:02 -07:00 committed by GitHub
parent 20f20e9fba
commit 7da1dfd21c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
```