I'm using the xpath engine on Firefox. I have html:
<span>
<b>prefix one</b> not bold part
</span>
<span>
prefix two not bold part
</span>
I want all the span
s that have child text that start with "prefix one".
I tried the xpath:
//span[starts-with(child::text(), "prefix one")]
but this doesn't work because the b
tag is interfering. How do you solve this?
thanks
The key part of this XPath is *[1] , which will select the node value of the first child of Department .
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
If you know that spans is not nested into other spans you can try this:
//span[ starts-with( descendant-or-self::*/text(),"prefix one" ) ]
descendant-or-self::*/text(),
should return all text nodes which are in this subtree. I don't know how starts-with()
exactly works but I suppose when some of text()
nodes in subtree starts with "prefix one" that condition is true
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