mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
parent
20f20e9fba
commit
7da1dfd21c
@ -156,3 +156,29 @@ page.locator("tag=div").get_by_text("click me").click()
|
|||||||
# we can use it in any methods supporting selectors.
|
# we can use it in any methods supporting selectors.
|
||||||
button_count = page.locator("tag=button").count()
|
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();
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user