This is my html code
<h2>==$0 "How" "Are You" </h2>
Writing locator like //h2/text()[1] for getting "How" text and writing //h2/text()[2] for getting "Are You" text doesn't works for me. Throws the below error
//h2/text()[1]
//h2/text()[2]
onException - WebDriver error: <font color= 'red' size='3.5'>org.openqa.selenium.InvalidSelectorException: invalid selector: The result of the xpath expression "//h2/text()[2]" is: [object Text]. It should be an element.
text() doesn't return webelement node but the text content
use instead
//*[text()[contains(.,"Are You")]]
now find the text as
elem.text()
you have to use string operator to extract the specific text you want
1.4m articles
1.4m replys
5 comments
57.0k users