-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathsample.csx
More file actions
31 lines (26 loc) · 943 Bytes
/
sample.csx
File metadata and controls
31 lines (26 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#r "Microsoft.Playwright.dll"
#r "Microsoft.Extensions.Logging.dll"
using Microsoft.Playwright;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
public class PlaywrightScript {
public static void Run(IBrowserContext context, ILogger logger) {
Execute(context, logger).Wait();
}
public static async Task Execute(IBrowserContext context, ILogger logger) {
var page = context.Pages.First();
if ( page.Url == "about:blank" ) {
var nextPage = context.Pages.Skip(1).First();
await page.CloseAsync();
page = nextPage;
}
foreach ( var frame in page.Frames ) {
if ( await frame.Locator("button:has-text('Button')").CountAsync() > 0 ) {
await frame.ClickAsync("button:has-text('Button')");
}
}
}
}