Buttons
Click, double click and right click – each one writes its own message, so you can prove which action happened.
You have done a single click
You have done a double click
You have done a right click
You clicked the button with the changing id
The last button gets a new random id on every page load – practise locating it by data-testid or by its text instead.
Practice tasks
- Click the first button and assert its message appears.
- Double click the second button using
Actions/dblclick()and assert only the double-click message appears. - Right click the third button and assert the right-click message appears.
- Reload the page twice and confirm the fourth button's
idchanges – then write a locator that still works.
Sample automation code
Actions actions = new Actions(driver);
driver.findElement(By.id("single-click-btn")).click();
Assert.assertTrue(driver.findElement(By.id("single-click-message")).isDisplayed());
actions.doubleClick(driver.findElement(By.id("double-click-btn"))).perform();
actions.contextClick(driver.findElement(By.id("right-click-btn"))).perform();
// changing id - locate by a stable attribute instead
driver.findElement(By.cssSelector("[data-testid='dynamic-id']")).click();
await page.getByTestId('single-click').click();
await expect(page.getByTestId('single-click-message')).toBeVisible();
await page.getByTestId('double-click').dblclick();
await page.getByTestId('right-click').click({ button: 'right' });
await page.getByTestId('dynamic-id').click();