List<WebElement> elements = driver.findElements(By.xpath("//div[contains(@class, 'pb-basket-item-price')]"));
for (WebElement element : elements) {
String str = element.getText();
System.out.println("original string: " + str);
if (str.contains("\"")) {
str = str.split("\"")[1];
}
System.out.println("this is what you need: " + str);
}
, below is the running log:
original string: 748 TL
this is what you need: 748 TL
original string: 499 TL "419 TL"
this is what you want: 419 TL
EDIT
Modify according to the question owner's comments.
Suppose: HTML looks like:
<div class="pb-basket-item-price">748 TL</div>
<div class="pb-basket-item-price">
<span>499 TL</span>
"419 TL"</div>
<div class="pb-basket-item-price">
<span>3.374,34 TL</span>
2.339 TL</div>
code:
List<WebElement> elements = driver.findElements(By.xpath("//div[contains(@class, 'pb-basket-item-price')]"));
for (WebElement element : elements) {
String str = element.getText();
int cntTL = (str.length() - str.replace("TL", "").length()) / 2;
if (2 == cntTL) {
str = str.split("TL")[1].replace("\"", "") + " TL";
}
System.out.println("this is what you need: " + str);
// str is what you want!
}