title: Selenium - XPATH - Searching for element by innerHTML
body: <p>I'm learning Selenium and have a decent grasp of XPATH.</p>
  
  <p>An issue I'm running into is that on a web page, there's an element I want to select that has a dynamically generated <code>id</code> and <code>class</code>. I had tried the following:</p>
  
  <pre><code>code = driver.find_element_by_xpath("//*[contains(@text='someUniqueString')]")
  </code></pre>
  
  <p>however, the element doesn't have any text. Instead it's a <code>&lt;code&gt;</code> element with JSON.</p>
  
  <pre><code>&lt;codestyle="display: none" id="something-crazy-dynamic"&gt; 
      {"dataIWantToGrab":{"someUniqueString":...}}
  &lt;/code&gt;
  </code></pre>
  
  <p>What I'm looking to do is search the <code>innerHTML</code> to find a unique string using XPATH but I can't find any good resources.</p>
  
  <p>I've tried </p>
  
  <pre><code>driver.find_element_by_xpath("//*[contains(@innerHTML='someUniqueString')]")
  </code></pre>
  
  <p>but am receiving the error</p>
  
  <pre><code>selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[contains(@innerHTML='someUniqueString')]
  </code></pre>
  
  <p>EDIT: Below is a link to the sibling text I'm working with</p>
  
  <p><a href="https://gist.github.com/anonymous/b227e59c942e7ec9f5a851a3b7ecdfc6" rel="noreferrer">https://gist.github.com/anonymous/b227e59c942e7ec9f5a851a3b7ecdfc6</a></p>
  
  <p>EDIT 2: I was able to get around this, not by using Selenium but with BeautifulSoup. Not ideal, but still a solution.</p>
  
  <pre><code>soup = BeautifulSoup(driver.page_source)
  codes = soup.find_all("code")
  found_json = [i for i in codes if i.text.find("someUniqueString") &gt; 0]
  </code></pre>