I am using XPath to query into HTML document where there is following div has text:
<div class="h1">2008 Honda Accord Coupe<small> — Wuse II</small></div>
I wanted to fetch only the inner text of the <div class="h1">2008 Honda Accord Coupe
and not include the <small>inner text</small>
I am making following XPath query: //div[@class='h1']
which is definitely returning entire <div>...</div>
node.
How can I only fetch portion without <small>...</small>
thanks
The XPath expression will return the reference of html element whose text contains the data entry. Innertext is used to select the node of innertext using XPath. The expression will specify the pattern which selects the xml nodes. XPath innertext is very useful and important.
The XPath text() function is a built-in function of selenium webdriver which is used to locate elements based on text of a web element. It helps to find the exact text elements and it locates the elements within the set of text nodes. The elements to be located should be in string form.
Use the text()
function:
//div[@class='h1']/text()
Tested in phpFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With