docs(dotnet): fix code snippets for GetByText
This commit is contained in:
parent
183720b56a
commit
a8ee6d0017
|
|
@ -256,7 +256,7 @@ print(page.evaluate("location.href"))
|
|||
```csharp
|
||||
var popup = await context.RunAndWaitForPageAsync(async =>
|
||||
{
|
||||
await page.GetByText("open new page").ClickAsync();
|
||||
await Page.GetByText("open new page").ClickAsync();
|
||||
});
|
||||
Console.WriteLine(await popup.EvaluateAsync<string>("location.href"));
|
||||
```
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ download.save_as("/path/to/save/at/" + download.suggested_filename)
|
|||
```csharp
|
||||
// Start the task of waiting for the download before clicking
|
||||
var waitForDownloadTask = page.WaitForDownloadAsync();
|
||||
await page.GetByText("Download file").ClickAsync();
|
||||
await Page.GetByText("Download file").ClickAsync();
|
||||
var download = await waitForDownloadTask;
|
||||
|
||||
// Wait for the download process to complete and save the downloaded file somewhere
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ locator.click()
|
|||
```
|
||||
|
||||
```csharp
|
||||
var locator = page.GetByText("Submit");
|
||||
var locator = Page.GetByText("Submit");
|
||||
await locator.HoverAsync();
|
||||
await locator.ClickAsync();
|
||||
```
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ file_chooser.set_files("myfile.pdf")
|
|||
```csharp
|
||||
var fileChooser = await page.RunAndWaitForFileChooserAsync(async () =>
|
||||
{
|
||||
await page.GetByText("Upload file").ClickAsync();
|
||||
await Page.GetByText("Upload file").ClickAsync();
|
||||
});
|
||||
await fileChooser.SetFilesAsync("temp.txt");
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1757,7 +1757,7 @@ new_email.click()
|
|||
|
||||
```csharp
|
||||
var newEmail = page.GetByRole(AriaRole.Button, new() { Name = "New" });
|
||||
var dialog = page.GetByText("Confirm security settings");
|
||||
var dialog = Page.GetByText("Confirm security settings");
|
||||
await Expect(newEmail.Or(dialog)).ToBeVisibleAsync();
|
||||
if (await dialog.IsVisibleAsync())
|
||||
await page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync();
|
||||
|
|
|
|||
|
|
@ -485,7 +485,7 @@ print(popup.evaluate("location.href"))
|
|||
```csharp
|
||||
var popup = await page.RunAndWaitForPopupAsync(async () =>
|
||||
{
|
||||
await page.GetByText("open the popup").ClickAsync();
|
||||
await Page.GetByText("open the popup").ClickAsync();
|
||||
});
|
||||
Console.WriteLine(await popup.EvaluateAsync<string>("location.href"));
|
||||
```
|
||||
|
|
@ -3186,7 +3186,7 @@ await page.get_by_role("button", name="Start here").click()
|
|||
|
||||
```csharp
|
||||
// Setup the handler.
|
||||
await page.AddLocatorHandlerAsync(page.GetByText("Sign up to the newsletter"), async () => {
|
||||
await page.AddLocatorHandlerAsync(Page.GetByText("Sign up to the newsletter"), async () => {
|
||||
await page.GetByRole(AriaRole.Button, new() { Name = "No thanks" }).ClickAsync();
|
||||
});
|
||||
|
||||
|
|
@ -3243,7 +3243,7 @@ await page.get_by_role("button", name="Start here").click()
|
|||
|
||||
```csharp
|
||||
// Setup the handler.
|
||||
await page.AddLocatorHandlerAsync(page.GetByText("Confirm your security details"), async () => {
|
||||
await page.AddLocatorHandlerAsync(Page.GetByText("Confirm your security details"), async () => {
|
||||
await page.GetByRole(AriaRole.Button, new() { Name = "Remind me later" }).ClickAsync();
|
||||
});
|
||||
|
||||
|
|
@ -3336,7 +3336,7 @@ await page.add_locator_handler(page.get_by_label("Close"), handler, times=1)
|
|||
```
|
||||
|
||||
```csharp
|
||||
await page.AddLocatorHandlerAsync(page.GetByText("Sign up to the newsletter"), async locator => {
|
||||
await page.AddLocatorHandlerAsync(Page.GetByText("Sign up to the newsletter"), async locator => {
|
||||
await locator.ClickAsync();
|
||||
}, new() { Times = 1 });
|
||||
```
|
||||
|
|
@ -4734,7 +4734,7 @@ with page.expect_navigation():
|
|||
await page.RunAndWaitForNavigationAsync(async () =>
|
||||
{
|
||||
// This action triggers the navigation after a timeout.
|
||||
await page.GetByText("Navigate after timeout").ClickAsync();
|
||||
await Page.GetByText("Navigate after timeout").ClickAsync();
|
||||
});
|
||||
|
||||
// The method continues after navigation has finished
|
||||
|
|
@ -4865,13 +4865,13 @@ second_request = second.value
|
|||
// Waits for the next request with the specified url.
|
||||
await page.RunAndWaitForRequestAsync(async () =>
|
||||
{
|
||||
await page.GetByText("trigger request").ClickAsync();
|
||||
await Page.GetByText("trigger request").ClickAsync();
|
||||
}, "http://example.com/resource");
|
||||
|
||||
// Alternative way with a predicate.
|
||||
await page.RunAndWaitForRequestAsync(async () =>
|
||||
{
|
||||
await page.GetByText("trigger request").ClickAsync();
|
||||
await Page.GetByText("trigger request").ClickAsync();
|
||||
}, request => request.Url == "https://example.com" && request.Method == "GET");
|
||||
```
|
||||
|
||||
|
|
@ -5009,13 +5009,13 @@ return response.ok
|
|||
// Waits for the next response with the specified url.
|
||||
await page.RunAndWaitForResponseAsync(async () =>
|
||||
{
|
||||
await page.GetByText("trigger response").ClickAsync();
|
||||
await Page.GetByText("trigger response").ClickAsync();
|
||||
}, "http://example.com/resource");
|
||||
|
||||
// Alternative way with a predicate.
|
||||
await page.RunAndWaitForResponseAsync(async () =>
|
||||
{
|
||||
await page.GetByText("trigger response").ClickAsync();
|
||||
await Page.GetByText("trigger response").ClickAsync();
|
||||
}, response => response.Url == "https://example.com" && response.Status == 200 && response.Request.Method == "GET");
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ var page = await context.NewPageAsync();
|
|||
await page.GotoAsync("https://playwright.dev");
|
||||
|
||||
await context.Tracing.StartChunkAsync();
|
||||
await page.GetByText("Get Started").ClickAsync();
|
||||
await Page.GetByText("Get Started").ClickAsync();
|
||||
// Everything between StartChunkAsync and StopChunkAsync will be recorded in the trace.
|
||||
await context.Tracing.StopChunkAsync(new()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1505,19 +1505,19 @@ page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE));
|
|||
|
||||
```csharp
|
||||
// Matches <span>
|
||||
page.GetByText("world");
|
||||
Page.GetByText("world");
|
||||
|
||||
// Matches first <div>
|
||||
page.GetByText("Hello world");
|
||||
Page.GetByText("Hello world");
|
||||
|
||||
// Matches second <div>
|
||||
page.GetByText("Hello", new() { Exact = true });
|
||||
Page.GetByText("Hello", new() { Exact = true });
|
||||
|
||||
// Matches both <div>s
|
||||
page.GetByText(new Regex("Hello"));
|
||||
Page.GetByText(new Regex("Hello"));
|
||||
|
||||
// Matches second <div>
|
||||
page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase));
|
||||
Page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase));
|
||||
```
|
||||
|
||||
**Details**
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ download.save_as("/path/to/save/at/" + download.suggested_filename)
|
|||
```csharp
|
||||
// Start the task of waiting for the download before clicking
|
||||
var waitForDownloadTask = page.WaitForDownloadAsync();
|
||||
await page.GetByText("Download file").ClickAsync();
|
||||
await Page.GetByText("Download file").ClickAsync();
|
||||
var download = await waitForDownloadTask;
|
||||
|
||||
// Wait for the download process to complete and save the downloaded file somewhere
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ popup.value.goto("https://wikipedia.org")
|
|||
```csharp
|
||||
var popup = await page.RunAndWaitForPopupAsync(async =>
|
||||
{
|
||||
await page.GetByText("open the popup").ClickAsync();
|
||||
await Page.GetByText("open the popup").ClickAsync();
|
||||
});
|
||||
await popup.GotoAsync("https://wikipedia.org");
|
||||
```
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ locator.click()
|
|||
```
|
||||
|
||||
```csharp
|
||||
var locator = page.GetByText("Submit");
|
||||
var locator = Page.GetByText("Submit");
|
||||
await locator.HoverAsync();
|
||||
await locator.ClickAsync();
|
||||
```
|
||||
|
|
|
|||
|
|
@ -301,23 +301,23 @@ page.get_by_text("Item").click(position={ "x": 0, "y": 0})
|
|||
await page.GetByRole(AriaRole.Button).ClickAsync();
|
||||
|
||||
// Double click
|
||||
await page.GetByText("Item").DblClickAsync();
|
||||
await Page.GetByText("Item").DblClickAsync();
|
||||
|
||||
// Right click
|
||||
await page.GetByText("Item").ClickAsync(new() { Button = MouseButton.Right });
|
||||
await Page.GetByText("Item").ClickAsync(new() { Button = MouseButton.Right });
|
||||
|
||||
// Shift + click
|
||||
await page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.Shift } });
|
||||
await Page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.Shift } });
|
||||
|
||||
// Ctrl + click or Windows and Linux
|
||||
// Meta + click on macOS
|
||||
await page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.ControlOrMeta } });
|
||||
await Page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.ControlOrMeta } });
|
||||
|
||||
// Hover over element
|
||||
await page.GetByText("Item").HoverAsync();
|
||||
await Page.GetByText("Item").HoverAsync();
|
||||
|
||||
// Click the top left corner
|
||||
await page.GetByText("Item").ClickAsync(new() { position = new Position { X = 0, Y = 0 } });
|
||||
await Page.GetByText("Item").ClickAsync(new() { position = new Position { X = 0, Y = 0 } });
|
||||
```
|
||||
|
||||
Under the hood, this and other pointer-related methods:
|
||||
|
|
@ -460,7 +460,7 @@ page.get_by_role("textbox").press("$")
|
|||
|
||||
```csharp
|
||||
// Hit Enter
|
||||
await page.GetByText("Submit").PressAsync("Enter");
|
||||
await Page.GetByText("Submit").PressAsync("Enter");
|
||||
|
||||
// Dispatch Control+Right
|
||||
await page.GetByRole(AriaRole.Textbox).PressAsync("Control+ArrowRight");
|
||||
|
|
@ -826,7 +826,7 @@ page.get_by_text("Footer text").scroll_into_view_if_needed()
|
|||
|
||||
```csharp
|
||||
// Scroll the footer into view, forcing an "infinite list" to load more content
|
||||
await page.GetByText("Footer text").ScrollIntoViewIfNeededAsync();
|
||||
await Page.GetByText("Footer text").ScrollIntoViewIfNeededAsync();
|
||||
```
|
||||
|
||||
If you would like to control the scrolling more precisely, use [`method: Mouse.wheel`] or [`method: Locator.evaluate`]:
|
||||
|
|
|
|||
|
|
@ -730,7 +730,7 @@ await page.get_by_text("Details").click()
|
|||
page.get_by_text("Details").click()
|
||||
```
|
||||
```csharp
|
||||
await page.GetByText("Details").ClickAsync();
|
||||
await Page.GetByText("Details").ClickAsync();
|
||||
```
|
||||
|
||||
```html
|
||||
|
|
@ -1265,7 +1265,7 @@ new_email.click()
|
|||
|
||||
```csharp
|
||||
var newEmail = page.GetByRole(AriaRole.Button, new() { Name = "New" });
|
||||
var dialog = page.GetByText("Confirm security settings");
|
||||
var dialog = Page.GetByText("Confirm security settings");
|
||||
await Expect(newEmail.Or(dialog).First).ToBeVisibleAsync();
|
||||
if (await dialog.IsVisibleAsync())
|
||||
await page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync();
|
||||
|
|
@ -1441,7 +1441,7 @@ page.getByText("orange").click();
|
|||
```
|
||||
|
||||
```csharp
|
||||
await page.GetByText("orange").ClickAsync();
|
||||
await Page.GetByText("orange").ClickAsync();
|
||||
```
|
||||
|
||||
#### Filter by text
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ await page.RouteAsync("*/**/api/v1/fruits", async route => {
|
|||
await page.GotoAsync("https://demo.playwright.dev/api-mocking");
|
||||
|
||||
// Assert that the Strawberry fruit is visible
|
||||
await Expect(page.GetByTextAsync("Strawberry")).ToBeVisibleAsync();
|
||||
await Expect(Page.GetByTextAsync("Strawberry")).ToBeVisibleAsync();
|
||||
```
|
||||
|
||||
```java
|
||||
|
|
@ -188,7 +188,7 @@ await page.RouteAsync("*/**/api/v1/fruits", async (route) => {
|
|||
await page.GotoAsync("https://demo.playwright.dev/api-mocking");
|
||||
|
||||
// Assert that the Loquat fruit is visible
|
||||
await Expect(page.GetByTextAsync("Loquat", new () { Exact = true })).ToBeVisibleAsync();
|
||||
await Expect(Page.GetByTextAsync("Loquat", new () { Exact = true })).ToBeVisibleAsync();
|
||||
```
|
||||
|
||||
```java
|
||||
|
|
@ -283,7 +283,7 @@ await page.RouteFromHARAsync("./hars/fruit.har", new () {
|
|||
await page.GotoAsync("https://demo.playwright.dev/api-mocking");
|
||||
|
||||
// Assert that the fruit is visible
|
||||
await Expect(page.GetByText("Strawberry")).ToBeVisibleAsync();
|
||||
await Expect(Page.GetByText("Strawberry")).ToBeVisibleAsync();
|
||||
```
|
||||
|
||||
```java
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ page.get_by_text("example domain").click()
|
|||
// Navigate and click element
|
||||
// Click will auto-wait for the element
|
||||
await page.GotoAsync("https://example.com");
|
||||
await page.GetByText("Example Domain").ClickAsync();
|
||||
await Page.GetByText("Example Domain").ClickAsync();
|
||||
```
|
||||
|
||||
For the scenario above, Playwright will wait for the text to become visible,
|
||||
|
|
@ -146,7 +146,7 @@ page.wait_for_url("**/login")
|
|||
```
|
||||
|
||||
```csharp
|
||||
await page.GetByText("Click me").ClickAsync();
|
||||
await Page.GetByText("Click me").ClickAsync();
|
||||
await page.WaitForURL("**/login");
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ response = response_info.value
|
|||
```csharp
|
||||
// Use a glob URL pattern
|
||||
var waitForResponseTask = page.WaitForResponseAsync("**/api/fetch_data");
|
||||
await page.GetByText("Update").ClickAsync();
|
||||
await Page.GetByText("Update").ClickAsync();
|
||||
var response = await waitForResponseTask;
|
||||
```
|
||||
|
||||
|
|
@ -397,12 +397,12 @@ response = response_info.value
|
|||
```csharp
|
||||
// Use a regular expression
|
||||
var waitForResponseTask = page.WaitForResponseAsync(new Regex("\\.jpeg$"));
|
||||
await page.GetByText("Update").ClickAsync();
|
||||
await Page.GetByText("Update").ClickAsync();
|
||||
var response = await waitForResponseTask;
|
||||
|
||||
// Use a predicate taking a Response object
|
||||
var waitForResponseTask = page.WaitForResponseAsync(r => r.Url.Contains(token));
|
||||
await page.GetByText("Update").ClickAsync();
|
||||
await Page.GetByText("Update").ClickAsync();
|
||||
var response = await waitForResponseTask;
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -464,7 +464,7 @@ parent = page.get_by_role("listitem").filter(has=child)
|
|||
```
|
||||
|
||||
```csharp
|
||||
var child = page.GetByText("Hello");
|
||||
var child = Page.GetByText("Hello");
|
||||
var parent = page.GetByRole(AriaRole.Listitem).Filter(new () { Has = child });
|
||||
```
|
||||
|
||||
|
|
@ -487,7 +487,7 @@ parent = page.get_by_text("Hello").locator('xpath=..')
|
|||
```
|
||||
|
||||
```csharp
|
||||
var parent = page.GetByText("Hello").Locator("xpath=..");
|
||||
var parent = Page.GetByText("Hello").Locator("xpath=..");
|
||||
```
|
||||
|
||||
## React locator
|
||||
|
|
@ -698,7 +698,7 @@ page.get_by_text("Password").fill("secret")
|
|||
|
||||
```csharp
|
||||
// Fill the input by targeting the label.
|
||||
await page.GetByText("Password").FillAsync("secret");
|
||||
await Page.GetByText("Password").FillAsync("secret");
|
||||
```
|
||||
|
||||
However, other methods will target the label itself, for example [`method: LocatorAssertions.toHaveText`] will assert the text content of the label, not the input field.
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ print(new_page.title())
|
|||
// Get page after a specific action (e.g. clicking a link)
|
||||
var newPage = await context.RunAndWaitForPageAsync(async () =>
|
||||
{
|
||||
await page.GetByText("open new tab").ClickAsync();
|
||||
await Page.GetByText("open new tab").ClickAsync();
|
||||
});
|
||||
// Interact with the new page normally
|
||||
await newPage.GetByRole(AriaRole.Button).ClickAsync();
|
||||
|
|
@ -288,7 +288,7 @@ print(popup.title())
|
|||
// Get popup after a specific action (e.g., click)
|
||||
var popup = await page.RunAndWaitForPopupAsync(async () =>
|
||||
{
|
||||
await page.GetByText("open the popup").ClickAsync();
|
||||
await Page.GetByText("open the popup").ClickAsync();
|
||||
});
|
||||
// Interact with the popup normally
|
||||
await popup.GetByRole(AriaRole.Button).ClickAsync();
|
||||
|
|
|
|||
|
|
@ -774,7 +774,7 @@ var page1 = await page.RunAndWaitForPopupAsync(async () =>
|
|||
|
||||
expect.soft(sources.get('C#')!.text).toContain(`
|
||||
await page.GotoAsync("about:blank");
|
||||
await page.GetByText("link").ClickAsync();`);
|
||||
await Page.GetByText("link").ClickAsync();`);
|
||||
|
||||
expect(page.url()).toContain('about:blank#foo');
|
||||
});
|
||||
|
|
@ -819,7 +819,7 @@ await page.GetByText("link").ClickAsync();`);
|
|||
.setButton(MouseButton.MIDDLE));`);
|
||||
|
||||
expect(sources.get('C#')!.text).toContain(`
|
||||
await page.GetByText("Click me").ClickAsync(new LocatorClickOptions
|
||||
await Page.GetByText("Click me").ClickAsync(new LocatorClickOptions
|
||||
{
|
||||
Button = MouseButton.Middle,
|
||||
});`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue