Goto Home and come back here using driver commanda

Get the X & Y co-ordinates of button

Find the color of the button

Find the height & width of the button

Confirm button is disabled

Click and Hold Button for 1.5 sec and verify button text

Click and Hold Button for 1.5 sec and verify button text

Right click on button

No action performed yet.

Insight

On completion of this exercise, you can learn the following concepts:

  1. click()
  2. getCss()
  3. getSize()
  4. isEnabled()
  5. getLocation()
  6. getText()
  7. double click
  8. right click
  9. driver navigation commands

Introduction

Buttons are the most commonly interacted element in web automation. Engineers must handle:

  1. Single click — basic click() action
  2. Double click — fires a different browser event
  3. Right click — opens the context menu
  4. Disabled button — assert it cannot be interacted with

Selenium uses the Actions class for advanced mouse interactions. Playwright has click options built in.

Key Methods Summary

Action Selenium (Java) Playwright (JS) Playwright (Python)
Single click element.click() locator.click() locator.click()
Double click actions.doubleClick(el).perform() locator.dblclick() locator.dblclick()
Right click actions.contextClick(el).perform() locator.click({ button: "right" }) locator.click(button="right")
Is disabled !isEnabled() toBeDisabled() to_be_disabled()
Get text getText() textContent() text_content()

1. Single Click

Selenium (Java)

driver.findElement(By.id("clickBtn")).click();
assertTrue(driver.findElement(By.id("clickResult")).isDisplayed());

Playwright (JS)

await page.locator("#clickBtn").click();
await expect(page.locator("#clickResult")).toBeVisible();

Playwright (Python)

page.locator("#clickBtn").click()
expect(page.locator("#clickResult")).to_be_visible()

2. Double Click

Selenium (Java)

WebElement btn = driver.findElement(By.id("doubleClickBtn"));
new Actions(driver).doubleClick(btn).perform();
 
assertEquals("Double clicked!", driver.findElement(By.id("doubleClickResult")).getText());

Playwright (JS)

await page.locator("#doubleClickBtn").dblclick();
await expect(page.locator("#doubleClickResult")).toHaveText("Double clicked!");

Playwright (Python)

page.locator("#doubleClickBtn").dblclick()
expect(page.locator("#doubleClickResult")).to_have_text("Double clicked!")

3. Right Click (Context Menu)

Selenium (Java)

WebElement btn = driver.findElement(By.id("rightClickBtn"));
new Actions(driver).contextClick(btn).perform();
 
assertTrue(driver.findElement(By.id("contextMenu")).isDisplayed());

Playwright (JS)

await page.locator("#rightClickBtn").click({ button: "right" });
await expect(page.locator("#contextMenu")).toBeVisible();

Playwright (Python)

page.locator("#rightClickBtn").click(button="right")
expect(page.locator("#contextMenu")).to_be_visible()

4. Disabled Button — verify it cannot be clicked

Selenium (Java)

WebElement btn = driver.findElement(By.id("disabledBtn"));
assertFalse(btn.isEnabled());
assertNotNull(btn.getAttribute("disabled"));

Playwright (JS)

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

Playwright (Python)

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

5. Verify button text changes after click

Selenium (Java)

WebElement btn = driver.findElement(By.id("toggleBtn"));
String before = btn.getText();
btn.click();
assertNotEquals(before, btn.getText());

Playwright (JS)

const btn = page.locator("#toggleBtn");
const before = await btn.textContent();
await btn.click();
expect(await btn.textContent()).not.toBe(before);

Playwright (Python)

btn = page.locator("#toggleBtn")
before = btn.text_content()
btn.click()
assert btn.text_content() != before

6. Click using keyboard Enter

Selenium (Java)

driver.findElement(By.id("submitBtn")).sendKeys(Keys.ENTER);

Playwright (JS)

await page.locator("#submitBtn").press("Enter");

Playwright (Python)

page.locator("#submitBtn").press("Enter")

📄 Also Read: Top 10 Best Automation Practice Website