Actions

Introduction

CSTesting for Python (C:\CSTesting-Python) drives the page with Playwright. All browser and locator actions are async—use await inside async def tests. Methods use snake_case (double_click, right_click, drag_and_drop). See cstesting/browser.py for the full API.

Text input

await browser.type(selector, text) or await locator.type(text) fills inputs and textareas (Playwright fill).

await browser.type("id=username", "Peter")
await browser.type("name=email", "user@example.com")

loc = browser.locator("id=username")
await loc.type("Peter")
await browser.locator("textarea").first().type("Hello")

Checkboxes and radio buttons

await browser.check(selector) / await locator.check() and uncheck for the opposite.

await browser.locator("id=agree").check()
await browser.check("name=subscribe")

await browser.locator("id=size-xl").check()
await browser.locator("name=size").nth(1).check()

Assert state with await browser.is_selected(selector) or await locator.is_selected() plus expect(...).to_be_truthy().

Select options

Pass a dict with value, label, or index, or a list of dicts for multi-select.

await browser.select("#color", {"value": "blue"})
await browser.select("#color", {"label": "Blue"})
await browser.select("#color", {"index": 2})

await browser.locator("#color").select({"value": "red"})

Mouse click

click, double_click, right_click, hover on page or locator.

await browser.locator("button").first().click()
await browser.click("id=submit")

await browser.locator(".item").first().double_click()
await browser.double_click("#item")

await browser.locator(".row").first().right_click()
await browser.right_click("#row")

await browser.locator("#menu").hover()

Playwright auto-scrolls elements into view before actions when needed.

Type characters

type/fill sets the whole value. For individual keys use await locator.press_key("Enter") or await browser.press_key("Tab").

await browser.locator("#area").type("Hello World!")
await browser.locator("#area").press_key("Enter")

Drag and drop

await browser.drag_and_drop("#source", "#target")

Locator-level drag between two locators is not exposed as a chain on LocatorApi; use the page-level drag_and_drop with selectors.

Scrolling

The Python API does not expose dedicated scroll_to_* helpers. Rely on Playwright scrolling elements into view before clicks, or run JS:

await browser.evaluate("window.scrollBy(0, 300)")
await browser.evaluate("document.querySelector('#footer').scrollIntoView()")