title: Selenium Python: find_element_by_css_selector() using :contains()
body: <p>In Selenium on Python, I'm trying to select an element using </p>
  
  <pre><code>driver = webdriver.Firefox()
  driver.find_element_by_css_selector("td:contains('hello world')")
  </code></pre>
  
  <p>Which gives me the error:</p>
  
  <pre><code>&gt;&gt;&gt;&gt; selenium.common.exceptions.WebDriverException: Message: u'An invalid or illegal string was specified' 
  </code></pre>
  
  <p>I can select elements using many different CSS selectors this way, but using :contains() always seems to throw an error.  NOTE: I get the same error when i try to use:</p>
  
  <pre><code>driver.find_element_by_xpath("//td[contains(text(),'hello world')]")
  </code></pre>
  
  <p>Please advise.  Thanks!</p>
  
  <p>EDIT: SOLVED!</p>
  
  <p>Problem solved!  Thank you so much for your help!  I had two significant mistakes:
  1.) I thought that :contains() was an accepted css3 selector (turns out it is not part of the current spec, which is why i couldn't select that way)
  2.) The xpath selector would have been fine except that I was using a parser that assumed xpath would never have any spaces in it, so it split the arguments by spaces.  Therefore, when i passed in the xpath selector</p>
  
  <pre><code>//td[contains(text(),'hello world']
  </code></pre>
  
  <p>the parser was truncated it at the space after 'hello' so the xpath selector looked like</p>
  
  <pre><code>//td[contains(text(),'hello
  </code></pre>
  
  <p>which clearly would throw an error.  So i need to adjust my parsing to properly read my xpath selector.</p>
  
  <p>Thank you again for all of your fast, helpful answers!</p>