Created
March 30, 2024 14:30
-
-
Save dhuynh95/0f9793d0d61966a4c1119dc80364ac35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from playwright.async_api import async_playwright | |
# Example on how to call these async functions using asyncio | |
import asyncio | |
async def load(): | |
# Example where we connect to a local existing Chrome session in debug mode | |
playwright = await async_playwright().start() | |
browser = await playwright.chromium.connect_over_cdp("http://localhost:9222") | |
default_context = browser.contexts[0] | |
# Retrieve the first page in the context. | |
page = default_context.pages[0] | |
# Navigate to the page. | |
return playwright, browser, page | |
async def goto(page): | |
await page.goto("https://www.united.com/en/us") | |
async def fill_origin_input(page): | |
origin_input = page.locator('input[placeholder="Origin"]') | |
# Fill the input field with an empty string (if needed to clear it) | |
await origin_input.fill('') | |
await origin_input.focus() | |
async def main(): | |
playwright, browser, page = await load() | |
await goto(page) | |
await fill_origin_input(page) | |
# Run the main function | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment