Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
721 views
by The go-to Tester (324 points)
closed by
Please describe how to capture and verify tool tip text in Selenium Webdriver?

Tool tips are very common elements of web page and visible on mouse hover of element. It can be on text box, link or anywhere else on the page. Sometimes we need to capture tool tip text In Selenium WebDriver to verify If text Is correct or not.
closed with the note: got it.

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

If your tooltip text is produced by HTML title attribute:

Usually tooltip text is specified in title attribute of an element. You can get the same by identifying the element and getting the title attribute.

E.g.

WebElement element = driver.findElement(By.cssSelector(".your text box"));

String toolTipText = element.getAttribute("title");
 
 
If your tooltip text is produced by JQuery:
 
It will not be a part of title attribute, it will actually highlight the div tag. In that case, you can use the Actions class to identify tool tip text.
 
E.g.
 
First, you have to mouse over to the element.
 
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.id("the text box"));
actions.moveToElement(element).build().perform();
 
Now you can get the tooltip text using .ui-tooltip class.
 
WebElement toolTipElement = driver.findElement(By.cssSelector(".ui-tooltip"));
Assert.assertEquals("We ask for your age only for statistical purposes.", toolTipText);
 
Hope that helps!
 
 
 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...