title: How to find element based on text and class with Selenium?
body: <p>I have an html table, and I want to find the <code>td</code> element in <code>tbody</code> based on the text  and if it doesn't contain a certain class. It should ignore anything in <code>thead</code> even if the text is present.</p>
  
  <pre><code>...
  
  &lt;div id="mytable"&gt;
      &lt;div&gt;
          &lt;table&gt;
              &lt;thead&gt;
                &lt;tr&gt;....&lt;/tr&gt;
                ...
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td class="inactive"&gt;3&lt;/td&gt;
                      &lt;td&gt;4&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  ...
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>def do_click(user_input):
      browser = webdriver.Firefox()
      browser.get(url)
  
      mytable_div = browser.find_element_by_id("mytable")
      element = mytable_div.find_element_by_xpath("//div/table/tbody/td[contains(text()='%s')]" % user_input)
  
      if element:
          element.click()
  </code></pre>
  
  <p>So if the <code>user_input = 3</code>, the table element <strong>should NOT</strong> be clicked because it has the class <code>inactive</code> even though the text is present.</p>
  
  <p>If the <code>user_input = 4</code>, then the table element <strong>should</strong> be clicked since it does not have a inactive class and the text is present.</p>
  
  <p>Currently the code doesn't work because my xpath expression is invalid, but I'm not sure what the correct way to check for both the class and the text would be.</p>