Reputation: 193
I want to create a method to Click on given element and open it in new tab. I manage to open new tab on click:
public async Task ClickMenuItemNewTab(string menuItem, string section, string header)
{
var context = BrowserSession.Browser.Contexts[0];
var newPage = await context.RunAndWaitForPageAsync(async () =>
{
await _homePage.ClickMenuItem(menuItem, section, header, new() { Button = MouseButton.Middle });
});
await newPage.WaitForLoadStateAsync();
}
but I don't know how can I switch to page in new tab. Do I have to create new browser context for it. Or is it way to switch to the page in same context. Thank you for any help.
Upvotes: 1
Views: 1574
Reputation: 11
await Page.BringToFrontAsync();
https://playwright.dev/dotnet/docs/api/class-page#page-bring-to-front
Upvotes: 0