This library allows you to type like a human in your Playwright automation scripts! 🤖⌨️
pip install humantyping[playwright]# Clone the repository
git clone https://github.com/yourusername/HumanTyping.git
cd HumanTyping
# Install with uv
uv sync --extra playwright
# Or install with pip
pip install -e .[playwright]import asyncio
from playwright.async_api import async_playwright
from humantyping import HumanTyper
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://example.com")
# Create a human typer (default: 60 WPM)
typer = HumanTyper()
# Or customize the typing speed
fast_typer = HumanTyper(wpm=90)
# Type into any input field
search_box = page.locator("input[name='search']")
await search_box.click()
await typer.type(search_box, "Hello, realistic typing!")
await browser.close()
asyncio.run(main())# Slow typer (40 WPM)
slow_typer = HumanTyper(wpm=40)
# Fast typer (100 WPM)
fast_typer = HumanTyper(wpm=100)# AZERTY keyboard
azerty_typer = HumanTyper(wpm=60, layout="azerty")
# QWERTY keyboard (default)
qwerty_typer = HumanTyper(wpm=60, layout="qwerty")import asyncio
from playwright.async_api import async_playwright
from humantyping import HumanTyper
async def google_search():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://google.com")
typer = HumanTyper(wpm=75)
# Type into Google search
search_input = page.locator("[name='q']")
await search_input.click()
await typer.type(search_input, "How to automate with Playwright")
# Press Enter
await search_input.press("Enter")
await page.wait_for_load_state("networkidle")
print(f"Search results loaded for: {await page.title()}")
await browser.close()
asyncio.run(google_search())HumanTyping simulates authentic human typing behavior:
✅ Variable Speed: Common words typed faster, complex words slower
✅ Natural Errors: Occasional typos on adjacent keys
✅ Swap Errors: Character inversions like "teh" → "the"
✅ Realistic Corrections: Uses Backspace or Arrow keys to fix mistakes
✅ Fatigue: Typing slows down slightly over long texts
✅ Natural Pauses: Brief delays between words
You can customize the behavior by editing src/config.py:
DEFAULT_WPM = 60 # Base typing speed
PROB_ERROR = 0.04 # 4% chance of typing errors
PROB_SWAP_ERROR = 0.015 # 1.5% swap errors
SPEED_BOOST_COMMON_WORD = 0.6 # 40% faster for common wordsMain class for realistic typing in Playwright.
Parameters:
wpm(float): Target words per minute (default: 60)layout(str): Keyboard layout - "qwerty" or "azerty" (default: "qwerty")
Methods:
Types text into a Playwright element with human-like behavior.
Parameters:
page_element: Playwright Locator or ElementHandletext(str): Text to type
Example:
typer = HumanTyper(wpm=70)
await typer.type(page.locator("#username"), "john_doe")Make sure to click the element before typing:
element = page.locator("input#field")
await element.click() # Important!
await typer.type(element, "text")Adjust the WPM parameter:
# Slower
typer = HumanTyper(wpm=30)
# Faster
typer = HumanTyper(wpm=120)Check the examples/ folder for:
playwright_example.py- Basic Playwright integrationselenium_example.py- Selenium integration (sync)
Built with ❤️ and maths.