Tool Tips
Tooltips that only appear while the mouse is over the element – you need Actions.moveToElement or hover().
Hover over this link as well.
Practice tasks
- Hover over the button and assert the tooltip appears with the right text.
- Move the mouse away and assert the tooltip disappears.
- Hover over the text field and assert the tooltip text is different from the button's.
- Assert that no tooltip is present in the DOM before you hover.
Sample automation code
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("tooltip-button"))).perform();
WebElement tip = new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("tooltip")));
Assert.assertEquals(tip.getText(), "You hovered over the button");
await page.getByTestId('tooltip-button').hover();
await expect(page.getByTestId('tooltip')).toHaveText('You hovered over the button');
await page.getByTestId('tooltip-input').hover();
await expect(page.getByTestId('tooltip')).toHaveText('You hovered over the text field');