title: Selenium Python : find element whose href attribute has required keyword
body: <p>The page I'm working on is in <strong><a href="http://www.ema.europa.eu/ema/index.jsp?curl=pages%2Fmedicines%2Flanding%2Fepar_search.jsp&amp;mid=WC0b01ac058001d124&amp;searchTab=searchByKey&amp;alreadyLoaded=true&amp;isNewQuery=true&amp;status=Authorised&amp;status=Withdrawn&amp;status=Suspended&amp;status=Refused&amp;keyword=abilify&amp;keywordSearch=Submit&amp;searchType=name&amp;taxonomyPath=&amp;treeNumber=&amp;searchGenericType=generics" rel="nofollow">this link</a></strong>.</p>
  
  <p>This is the relevant portion of that page:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; 
    &lt;head&gt;...&lt;/head&gt;
    &lt;body&gt;
      ...
      &lt;div id="searchResults"&gt;
        &lt;div class="box-related"&gt;...&lt;/div&gt;
        &lt;a href='downloadDataServlet?category=true&amp;amp;type=epar' onclick=""&gt;&lt;img src="/ema/images/icon_download_spread.gif" /&gt;Download results to spreadsheet&lt;/a&gt;
        &lt;div class="table-holder"&gt;
          &lt;table class="table-epar eparResults" border="1" cellpadding="0" cellspacing="0" summary="Search results for EPARs ordered alphabetically"&gt;
            &lt;caption&gt;EPAR Search results&lt;/caption&gt;
            &lt;thead&gt; ... &lt;/thead&gt;
            &lt;tbody&gt;
              &lt;tr&gt;
                &lt;th scope="row" class="key-detail name word-wrap"&gt;
                  &lt;a href="index.jsp?curl=pages/medicines/human/medicines/000471/human_med_000619.jsp&amp;amp;mid=WC0b01ac058001d124"&gt;Abilify&lt;/a&gt;
                &lt;/th&gt;
                ...
              &lt;/tr&gt;
              &lt;tr&gt;...&lt;/tr&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the XPath location of the element I wish to select:</p>
  
  <pre><code>//*[@id="searchResults"]/div[2]/table/tbody/tr[1]/th/a
  </code></pre>
  
  <p>But there may be many results on the searchpage, so I want to click on the link whose URL has the product number that I'm searching for (which is <code>000471</code> in this case). I want to select the <code>&lt;a&gt;</code> element which contains that string in the <code>href</code> attribute.</p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>inp = driver.find_element_by_xpath("//*[@id='searchResults']/div[2]/table/tbody/tr[1]/th/a[contains(@href,'"+str3+"')]")
  inp.click()
  </code></pre>
  
  <p>where <code>str3</code> has the value <code>000471</code> in this case. But I keep getting <code>NoSuchElementException</code>.</p>
  
  <p>Any help would be appreciated!</p>