Selenium Jana- How to get the desired value from inside a <i> tag

<i data-html="true" data-placement="top" data-trigger="hover" data-original-title="Backend Offer Details" data-content="<dl class='dl-horizontal itemCodeHolder'><dt>Code : </dt><dd>BPAZ3XG</dd><dt>SOC : </dt><dd>No Matching SOC</dd></dl>" data-toggle="popover" class="icon-info-sign boPopover"></i>    

How to get a value from something like this. This is a tool-tip and I want the to get BPAZ3XG from the above tag. How is it possible in Selenium.


I'm not sure if you have a locator for the i element or not yet so I added code for one in case you didn't. For the i locator, I am assuming that the data-original-title='Backend Offer Details' is unique on the page. If it isn't, you'll have to adjust it.

Basically I find the i element, get the data-content attribute (which is a small HTML/XML snippet), and then look for the text in the first dd tag. NOTE: there are two dd tags in the data-content HTML snippet.

WebElement element = driver.findElement(By.cssSelector("i[data-original-title='Backend Offer Details']"));
String dataContent = element.getAttribute("data-content");
System.out.println(dataContent.substring(dataContent.indexOf("<dd>") + 4, dataContent.indexOf("</dd>")));

if your target element "BPAZ3XG" is having no duplicates in web application, you can try with contains text, as i mentioned below


To break this down,

*is a selector that matches any element (i.e. tag) -- it returns a node-set.

The [] are a conditional that operates on each individual node in that node set. It matches if any of the individual nodes it operates on match the conditions inside the brackets.

text() is a selector that matches all of the text nodes that are children of the context node -- it returns a node set.

contains is a function that operates on a string. If it is passed a node set, the node set is converted into a string by returning the string-value of the node in the node-set that is first in document order

Need Your Help

What language/API to use for a standalone live-input audio visualizer app?

objective-c actionscript-3 air audio

I develop with Actionscript and was glad to see that AIR 2.0 was going to give access to mic input data. I planned to use this to create a visualizer set to the tempo of the incoming live audio. Af...

How to allow DTD in XML Documents loaded via XSLT's document(uri) function with XslCompiledTransform (.NET)

.net xslt

When the document(uri) function is used to load another document within the XSLT, where the target document contains a DTD I get an XslTransformException, containing an inner XmlException: