Get tooltip from number input using selenium

418 views Asked by At

I need to get tooltip from standard element, for example:

<input class="some_class" type="number" value="0" name="some_name"/>

I have no attributes which set tooltip on this element like "title" or maybe "alt" or something else. Browser generates tootltips by itself and it is default feature. For example, if i will set text value to this input i will get tooltip "Please enter a number" in Firefox.

Question is how to get text of this tooltip from java code using Selenium?

I guess that i need to make MouseOver event over my input and tooltip will be shown. I can do it. But i can't understand how to get text of this showing tooltip from code. What XPath expression maybe should i write to get access to this tooltip? Or maybe there is some core method for these purposes?

2

There are 2 answers

1
peetya On

Here is the cssSelector for the tooltip:

input::-webkit-validation-bubble-message

I found it here, maybe it helps you: http://www.useragentman.com/blog/2012/05/17/cross-browser-styling-of-html5-forms-even-in-older-browsers/

1
Gaspar On

Try this

Actions toolTip = new Actions(driver);
WebElement ele = driver.findElement(By.xpath("your_xpath"));
toolTip.clickAndHold(ele).perform(); 
String ToolTipText = ele.getText();

or

String ToolTipText = ele.getAttribute("title")