-1

Search with word Food, but after searching it is displaying under double quotes as "Food".

Used.

driver.findElement(By.xpath("")).getText();

HTML:

<header class="search-top"> 
    <h1 id="results_header" class="home genrecontainer"> Search Results for 
        <span>"food"</span> 
    </h1> 
</header> 

enter image description here

Andersson
  • 51,635
  • 17
  • 77
  • 129

2 Answers2

0

Without seeing the html it is difficult to provide you with an xpath that achieves this. You can just use Javas subString() method to achieve this:

String text = driver.findElement(By.xpath(".//*[@id='results_header']/span")).getText();
String trimmedText = text.subString(1, text.length()-1);
Cathal
  • 1,318
  • 1
  • 12
  • 19
0

First get the text under span tag:

String searchKey = driver.findElement(By.cssSelector("#results_header > span")).getText();

Now, use replaceAll() method to remove quotes:

String yourDesiredValueWithoutQuotes = searchKey.replaceAll("\"", "");
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37