title: Exact match for string using XPath
body: <p>I wrote an xpath to scrape elements from a web page using selenium c#. </p>
  
  <p>Here is the XPath</p>
  
  <pre><code>tbody/tr[@backcolor]/td/b/a[contains(text(),"match text")]
  </code></pre>
  
  <p>This is working fine until I found duplicates coming for <code>match text</code>. So, on a web page I've two elements with the <code>match text</code></p>
  
  <p>one with <code>match text</code> and the other with <code>match text 9000</code></p>
  
  <p>Now, I only need to perform clicking for <code>match text</code>. So, I wrote the following XPath</p>
  
  <pre><code>table/tbody/tr[@bgcolor]/td/b/a[text()="   match text"]
  </code></pre>
  
  <p>Note that the match text has leading spaces on the web page. The above Xpath didn't worked. I've checked this with <code>Fire Path</code> extension for Firefox.</p>
  
  <p>Can anyone suggest me a Xpath, which finds the exact match for the <code>match text</code>. Assume that the match text can contain any number of leading spaces. </p>
  
  <p>I've also tried using the <code>normalize-space()</code> but that didn't work either. This is what I've tried </p>
  
  <pre><code>text()[normalize-space(.)='match']
  </code></pre>
  
  <p>I found some questions on SO, which didn't help.</p>
  
  <p>Appreciate your help.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Thanks for your answers but none of them worked for me.</p>
  
  <p>Also I've mentioned these two strings</p>
  
  <ul>
  <li>match text </li>
  <li>match text 9000</li>
  </ul>
  
  <p>In my code I'll be iterating them over foreach loop. So, I cannot guarantee that I'll get 9000 as the second element. </p>
  
  <p>I've tried all the answers mentioned using FirePath extension for Firefox, but nothing is selected on the web page.</p>
  
  <p>As mentioned earlier I've leading spaces before the match text.</p>
  
  <p><strong>HTML:</strong> (To match the xpath)</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;table&gt;
  &lt;tbody&gt;
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;a class="s7intext" href="#"&gt;&amp;nbsp;&amp;nbsp; match text&lt;/a&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;a class="s7intext" href="#"&gt;&amp;nbsp;&amp;nbsp; match text random&lt;/a&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the HTML in my page, which has <code>&amp;nbsp;</code> characters. There are two <code>&amp;nbsp;</code> characters and an additional space before <code>match text</code>. The site that I'm scraping the elements is a client site. I cannot say him to modify his HTML on it.</p>