|
| 1 | +/* |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.example; |
| 18 | + |
| 19 | +import com.microsoft.playwright.*; |
| 20 | + |
| 21 | +public class SelectorsAndKeyboardManipulation { |
| 22 | + public static void main(String[] args) { |
| 23 | + try(Playwright playwright = Playwright.create()) { |
| 24 | + Browser browser = playwright.firefox().launch(); |
| 25 | + BrowserContext context = browser.newContext(); |
| 26 | + Page page = context.newPage(); |
| 27 | + page.navigate("https://playwright.dev/java/"); |
| 28 | + page.locator("text=SearchK").click(); |
| 29 | + page.locator("[placeholder=\"Search docs\"]").fill("getting started"); |
| 30 | + page.locator("div[role=\"button\"]:has-text(\"CancelIntroductionGetting startedInstallationGetting startedUsageGetting start\")").click(); |
| 31 | + page.waitForSelector("h1:has-text(\"Getting started\")"); // Waits for the new page to load before screenshotting. |
| 32 | + page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("Screenshot.png"))); |
| 33 | + } |
| 34 | + } |
| 35 | +} |
0 commit comments