Beginner 15 min 6 scenarios

Input Field Automation Practice

Master text input interactions in Selenium & Playwright — typing, clearing, reading values, and detecting disabled/readonly states.

Scenario 1: Movie Name Input

Tab



DISABLED

READ-ONLY

What You'll Learn

Selenium (Java)

  • sendKeys()
  • clear()
  • getAttribute()
  • isEnabled()
  • Keys.TAB
Tutorial video coming soon

Test Cases

Introduction

Input fields are the foundation of form automation. Common scenarios include:

  1. Type into a fieldsendKeys / fill
  2. Clear a field — remove existing text before typing
  3. Read the current valuegetAttribute("value")
  4. Check disabled inputs — field exists but cannot be edited
  5. Check readonly inputs — field displays text but rejects keyboard input

Key Methods Summary

Action Selenium (Java) Playwright (JS) Playwright (Python)
Type text sendKeys("text") fill("text") fill("text")
Clear field clear() fill("") fill("")
Read value getAttribute("value") inputValue() input_value()
Is disabled !isEnabled() toBeDisabled() to_be_disabled()
Is readonly getAttribute("readonly") toHaveAttribute("readonly", "") to_have_attribute(...)
Press Tab sendKeys(Keys.TAB) press("Tab") press("Tab")

1. Type text into an input field

Selenium (Java)

driver.findElement(By.id("movieName")).sendKeys("Inception");

Playwright (JS)

await page.fill("#movieName", "Inception");

Playwright (Python)

page.fill("#movieName", "Inception")

2. Append text and press Tab

⚠️ Note: Playwright's fill() clears the field before typing. To truly append existing text, use click() + keyboard.type() instead.

Selenium (Java)

WebElement field = driver.findElement(By.id("appendText"));
field.sendKeys(" and feeling great");
field.sendKeys(Keys.TAB);

Playwright (JS)

// click to focus, then type to append (fill() would clear first)
await page.locator("#appendText").click();
await page.keyboard.press("End");
await page.keyboard.type(" and feeling great");
await page.locator("#appendText").press("Tab");

Playwright (Python)

# click to focus, then type to append (fill() would clear first)
page.locator("#appendText").click()
page.keyboard.press("End")
page.keyboard.type(" and feeling great")
page.locator("#appendText").press("Tab")

3. Verify text present inside an input field

Selenium (Java)

String value = driver.findElement(By.id("insideText")).getAttribute("value");
assertEquals("QA PlayGround", value);

Playwright (JS)

await expect(page.locator("#insideText")).toHaveValue("QA PlayGround");

Playwright (Python)

expect(page.locator("#insideText")).to_have_value("QA PlayGround")

4. Clear an input field

Selenium (Java)

WebElement field = driver.findElement(By.id("clearText"));
field.clear();
assertEquals("", field.getAttribute("value"));

Playwright (JS)

await page.locator("#clearText").fill("");
await expect(page.locator("#clearText")).toHaveValue("");

Playwright (Python)

page.locator("#clearText").fill("")
expect(page.locator("#clearText")).to_have_value("")

5. Check an input is disabled

Selenium (Java)

WebElement disabledInput = driver.findElement(By.id("disabledInput"));
assertFalse(disabledInput.isEnabled());

Playwright (JS)

await expect(page.locator("#disabledInput")).toBeDisabled();

Playwright (Python)

expect(page.locator("#disabledInput")).to_be_disabled()

6. Check an input is readonly

Selenium (Java)

WebElement readonlyInput = driver.findElement(By.id("readonlyInput"));
assertNotNull(readonlyInput.getAttribute("readonly"));
// Attempt to type — it won't change
readonlyInput.sendKeys("test");
assertEquals("This text is readonly", readonlyInput.getAttribute("value"));

Playwright (JS)

await expect(page.locator("#readonlyInput")).toHaveAttribute("readonly", "");
await page.locator("#readonlyInput").fill("test"); // no effect
await expect(page.locator("#readonlyInput")).toHaveValue("This text is readonly");

Playwright (Python)

expect(page.locator("#readonlyInput")).to_have_attribute("readonly", "")
page.locator("#readonlyInput").fill("test")  # no effect
expect(page.locator("#readonlyInput")).to_have_value("This text is readonly")

📄 Also Read: Top 10 Best Automation Practice Website