title: Finding an element by partial href (Python Selenium)
body: <p>I'm trying to access text from elements that have different xpaths but very predictable href schemes across multiple pages in a web database. Here are some examples:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;a href="/mathscinet/search/mscdoc.html?code=65J22,(35R30,47A52,65J20,65R30,90C30)"&gt;
  65J22 (35R30 47A52 65J20 65R30 90C30) &lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In this example I would want to extract "65J22 (35R30 47A52 65J20 65R30 90C30)"</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;a href="/mathscinet/search/mscdoc.html?code=05C80,(05C15)"&gt;
  05C80 (05C15) &lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In this example I would want to extract "05C80 (05C15)". My web scraper would not be able to search by xpath directly due to the xpaths of my desired elements changing between pages, so I am looking for a more roundabout approach.</p>
  
  <p>My main idea is to use the fact that every href contains "/mathscinet/search/mscdoc.html?code=". Selenium can't directly search for hrefs, but I was thinking of doing something similar to this <a href="https://stackoverflow.com/questions/28572892/selenium-how-to-find-element-by-partial-href">C# implementation</a>:</p>
  
  <pre><code>Driver.Instance.FindElement(By.XPath("//a[contains(@href, 'long')]"))
  </code></pre>
  
  <p>To port this over to python, the only analogous method I could think of would be to use the <a href="https://docs.python.org/reference/expressions.html#membership-test-details" rel="nofollow noreferrer"><code>in</code> operator</a>, but I am not sure how the syntax will work when everything is nested in a find_element_by_xpath. How would I bring all of these ideas together to obtain my desired text?</p>
  
  <pre><code>driver.find_element_by_xpath("//a['/mathscinet/search/mscdoc.html?code=' in @href]").text
  </code></pre>