Reputation: 201
I have this html :
<div class="b-datalist__item__subj">
hello
<span class="b-datalist__item__subj__snippet">hello world</span>
</div>
And I want to get only "hello"
text, without "hello world"
. I write this code:
subject = this.driver.findElement(By.xpath("//div[@class = 'b-datalist__item__subj']")).getText();
But in console output I see "hellohello world"
. How can I fix it?
Upvotes: 1
Views: 4534
Reputation: 10329
You will have to "subtract" the text inside the span
from the complete text in the div
. Something like:
String outsideText = driver.findElement(By.xpath("//div")).getText();
String insideText = driver.findElement(By.xpath("//span")).getText();
String yourText = outsideText.replace(insideText, "");
Adjust the XPaths as necessary for your situation.
Upvotes: 2