title: Selenium: How to locate an exact text match when there are several occurence of the text
body: <p>I'm looking for a solution with this small selenium script. The problem happens when on the list there are more than 1 occurence of the text. i'm looking for in with xpath command[contains(). Then script stops.</p>
  
  <p>As you see on my script tried to use css selector (un-commented) but it not valid. I have seen some solution with regular expression with css selector with ^ and $ but i don't how it works. </p>
  
  <p>EDIT: I'm looking to select only the third element "LIT" as you see there are thee times LIT inside de  list which block the  script.</p>
  
  <p>Here is the snippet html</p>
  
  <pre><code>&lt;div class="prodUnitCat"&gt;
  &lt;ul class="fixFacetZindex clearBoth" id="divChildrenCategoryFilter_0"&gt;
  /ul&gt;
  &lt;ul data-lvlcat="2"&gt;
  &lt;li data-idcat="1000015739"&gt;&lt;span&gt;ACCESSOIRES LITERIE&lt;/span&gt; (9)&lt;/li&gt;
  &lt;li data-idcat="1000015760"&gt;&lt;span&gt;ELEMENT DE LIT&lt;/span&gt; (5)&lt;/li&gt;
  &lt;li data-idcat="1000015773"&gt;&lt;span&gt;LIT&lt;/span&gt; (9)&lt;/li&gt;
  &lt;li data-idcat="1000015794"&gt;&lt;span&gt;LIT D'APPOINT&lt;/span&gt; (2)&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and here my code</p>
  
  <pre><code>  prod = db.select(sql)
    for record in prod:
  
  
          cat1       = record[10]
          cat2       = record[11]
          cat3       = record[12]
          cat4       = record[13]
  
          # loading check
          WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(headerFieldID))
  
  
          # cat selection
          driver.find_element_by_xpath(u"//span[contains(text(),'" + cat1 +"')]").click()
          driver.find_element_by_xpath(u"//span[contains(text(),'" + cat2 + "')]").click()
          #driver.find_element_by_css_selector("span[contains('" + cat2 +"')]").click()
          driver.find_element_by_xpath(u"//span[contains(text(),'" + cat3 + "')]").click()
          driver.find_element_by_xpath(u"//div[@id=\"categContent\"]/div[4]/ul/li/span[contains(text(),'" + cat4 + "')]").click()
          loginButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath))
          loginButtonElement.click()
  </code></pre>