Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a tooltip text on mouseover using Selenium WebDriver

I am not able to get tooltip text after mouseover on icon tooltip. I need to get tooltip text,This is html code.

<a class="tooltip" onclick="SocialAuth.showOpenIDLoginWindow('google');_gaq.push(['_trackEvent','LoginForm','google-login','google login was clicked']);" href="javascript:void(0);"><span>We dont store your password or access your contacts on your Google account.</span><img class="social" height="39" width="40" src="/images/login/google.png"/>
like image 626
Raghu Avatar asked Oct 07 '13 06:10

Raghu


People also ask

What is hover tooltip?

A tooltip is a user interface component containing text that appears when a user hovers their cursor over an element.

How do you find the tooltip of an element?

Basic Tooltip HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .


1 Answers

The method to get text from a tool tip differs from a HTML one when its a Jquery ToolTip. getAttribute() does not work when its a Jquery ToolTip. If you see the tooltip example at http://demoqa.com/tooltip/ , its a jquery tooltip.

Following code works here:

    WebDriver driver=new FirefoxDriver();
    driver.get("http://demoqa.com/tooltip/");
    WebElement element = driver.findElement(By.xpath(".//*[@id='age']"));
    Actions toolAct = new Actions(driver);
    toolAct.moveToElement(element).build().perform();
    WebElement toolTipElement = driver.findElement(By.cssSelector(".ui-tooltip"));
    String toolTipText = toolTipElement.getText();
    System.out.println(toolTipText);

A good reference is:

http://www.seleniumeasy.com/selenium-tutorials/how-to-verify-tooltip-text-with-selenium-webdriver-using-java

like image 190
Arup Basu Avatar answered Jan 02 '23 22:01

Arup Basu