I have some span's like this:
<span>
<span>foobar</span>
<span>thisisatest</span>
</span>
I'm trying to use xpath to find the span with "thisisatest" in it.
I've tried this:
span[text()='thisisatest']
and it doesn't seem to be working.
We can select the text of a span on click with Selenium webdriver. To identify the element with span tag, we have to first identify it with any of the locators like xpath, css, class name or tagname. After identification of the element, we can perform the click operation on it with the help of the click method.
You can use By. XPath with the code you have Inner text is text between the opening tags and closing tags. For example: <a>I Am Inner Text</a> In above example, texts “I Am Inner Text” between opening and closing tags are called inner text of web element “a”.
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.
A Parent of a context node is selected Flat element. A string of elements is normally separated by a slash in an XPath statement. You can pick the parent element by inserting two periods “..” where an element would typically be. The parent of the element to the left of the double period will be selected.
You are missing //
at the beginning of the XPath.
//span[text()='thisisatest']
You could try this:
span[span= "thisisatest"]
All <span>
elements that contain at least one <span>
element child with the value thisisatest.
Hope it helps!
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