I asked this question today, but mistakenly I did not specify the scope of it, which is for use in Selenium Webdriver.
So I have this td:
<td>
<span id="PartComment">
REMAN WATER PUMP
<i>w/2.05" DIAMETER THERMOSTAT OUTLET - SUPPLIED w/PULLEY
</i>
</span>
</td>
And I want an xpath to locate only the text REMAN WATER PUMP to later convert it to a string.
driver.findElement(By.xpath("//span[@id='lblPartComment']/text()"));
But the problem is that since I'm only locating the text, and not a DOM object, WebDriver won't be able to treat it as such:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector //span[@id='lblPartComment']/text() is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: The result of the xpath expression "//span[@id='lblPartComment']/text()" is: [object Text]. It should be an element.
Can you please provide an alternative to that xpath? One that locates the text I mentioned above, and excludes the text inside the i
?
Also, related.
Thanks