Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dotnet code snippets for text and goto #33382

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-download.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-elementhandle.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ locator.click()
```

```csharp
var locator = page.GetByText("Submit");
var locator = Page.GetByText("Submit");
await locator.HoverAsync();
await locator.ClickAsync();
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-filechooser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ browser.close()
```

```csharp
await page.GotoAsync("https://keycode.info");
await Page.GotoAsync("https://keycode.info");
await page.Keyboard.PressAsync("A");
await page.ScreenshotAsync(new() { Path = "A.png" });
await page.Keyboard.PressAsync("ArrowLeft");
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-locator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-locatorassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ expect(page.locator('body')).to_match_aria_snapshot('''
```

```csharp
await page.GotoAsync("https://demo.playwright.dev/todomvc/");
await Page.GotoAsync("https://demo.playwright.dev/todomvc/");
await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@"
- heading ""todos""
- textbox ""What needs to be done?""
Expand Down
24 changes: 12 additions & 12 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
```
Expand Down Expand Up @@ -3186,12 +3186,12 @@ 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();
});

// Write the test as usual.
await page.GotoAsync("https://example.com");
await Page.GotoAsync("https://example.com");
await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync();
```

Expand Down Expand Up @@ -3243,12 +3243,12 @@ 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();
});

// Write the test as usual.
await page.GotoAsync("https://example.com");
await Page.GotoAsync("https://example.com");
await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync();
```

Expand Down Expand Up @@ -3305,7 +3305,7 @@ await page.AddLocatorHandlerAsync(page.Locator("body"), async () => {
}, new() { NoWaitAfter = true });

// Write the test as usual.
await page.GotoAsync("https://example.com");
await Page.GotoAsync("https://example.com");
await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync();
```

Expand Down Expand Up @@ -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 });
```
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
```

Expand Down Expand Up @@ -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");
```

Expand Down
6 changes: 3 additions & 3 deletions docs/src/api/class-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ print(response.request.redirected_from.url) # "http://example.com"
```

```csharp
var response = await page.GotoAsync("http://www.microsoft.com");
var response = await Page.GotoAsync("http://www.microsoft.com");
Console.WriteLine(response.Request.RedirectedFrom?.Url); // http://www.microsoft.com
```

Expand All @@ -241,7 +241,7 @@ print(response.request.redirected_from) # None
```

```csharp
var response = await page.GotoAsync("https://www.google.com");
var response = await Page.GotoAsync("https://www.google.com");
Console.WriteLine(response.Request.RedirectedFrom?.Url); // null
```

Expand Down Expand Up @@ -368,7 +368,7 @@ print(request.timing)
```csharp
var request = await page.RunAndWaitForRequestFinishedAsync(async () =>
{
await page.GotoAsync("https://www.microsoft.com");
await Page.GotoAsync("https://www.microsoft.com");
});
Console.WriteLine(request.Timing.ResponseEnd);
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
10 changes: 5 additions & 5 deletions docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
4 changes: 2 additions & 2 deletions docs/src/clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ assertThat(page.getByText("You have been logged out due to inactivity.")).isVisi
```csharp
// Initial time does not matter for the test, so we can pick current time.
await Page.Clock.InstallAsync();
await page.GotoAsync("http://localhost:3333");
await Page.GotoAsync("http://localhost:3333");

// Interact with the page
await page.GetByRole("button").ClickAsync();
Expand Down Expand Up @@ -375,7 +375,7 @@ await Page.Clock.InstallAsync(new()
{
TimeDate = new DateTime(2024, 2, 2, 8, 0, 0, DateTimeKind.Pst)
});
await page.GotoAsync("http://localhost:3333");
await Page.GotoAsync("http://localhost:3333");
var locator = page.GetByTestId("current-time");

// Pause the time flow, stop the timers, you now have manual control
Expand Down
2 changes: 1 addition & 1 deletion docs/src/downloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/src/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ print(first.value.url)

```csharp
var waitForRequestTask = page.WaitForRequestAsync("**/*logo*.png");
await page.GotoAsync("https://wikipedia.org");
await Page.GotoAsync("https://wikipedia.org");
var request = await waitForRequestTask;
Console.WriteLine(request.Url);
```
Expand Down Expand Up @@ -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");
```
Expand Down Expand Up @@ -152,11 +152,11 @@ void listener(object sender, IRequest request)
Console.WriteLine("Request finished: " + request.Url);
};
page.RequestFinished += listener;
await page.GotoAsync("https://wikipedia.org");
await Page.GotoAsync("https://wikipedia.org");

// Remove previously added listener.
page.RequestFinished -= listener;
await page.GotoAsync("https://www.openstreetmap.org/");
await Page.GotoAsync("https://www.openstreetmap.org/");
```

## Adding one-off listeners
Expand Down
2 changes: 1 addition & 1 deletion docs/src/handles.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ locator.click()
```

```csharp
var locator = page.GetByText("Submit");
var locator = Page.GetByText("Submit");
await locator.HoverAsync();
await locator.ClickAsync();
```
16 changes: 8 additions & 8 deletions docs/src/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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`]:
Expand Down
6 changes: 3 additions & 3 deletions docs/src/locators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1441,7 +1441,7 @@ page.getByText("orange").click();
```

```csharp
await page.GetByText("orange").ClickAsync();
await Page.GetByText("orange").ClickAsync();
```

#### Filter by text
Expand Down
Loading
Loading