title: Python: why driver.find_element_by_class_name gives no such element: Unable to locate element
body: <p>Currently I'm working with Selenium trying properly identify elements using 'Inspect' from Chrome.
  In certain cases some of my buttons to click defined only by class, however certain classes are failed to be found using''' driver.find_element_by_class_name '''.</p>
  <p>Here is the peace of code I retrive with Inspect from Chrome:</p>
  <pre><code>  &lt;td class=&quot;x-toolbar-cell&quot; id=&quot;ext-gen1328&quot; role=&quot;menuitem&quot;&gt;
    &lt;table id=&quot;ImportMenuSmartExpReport&quot; cellspacing=&quot;0&quot; class=&quot;x-btn grayBtn x-btn-text-icon&quot; role=&quot;presentation&quot; style=&quot;width: auto;&quot;&gt;
     &lt;tbody class=&quot;x-btn-small x-btn-icon-small-left&quot;&gt;
      &lt;tr&gt;
       &lt;td class=&quot;x-btn-tl&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-tc&quot;&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-tr&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td class=&quot;x-btn-ml&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-mc&quot;&gt;&lt;em class=&quot;&quot; unselectable=&quot;on&quot;&gt;&lt;button type=&quot;button&quot; id=&quot;ext-gen1329&quot; class=&quot; x-btn-text menu_import2&quot;&gt;Import Expenses&lt;/button&gt;&lt;/em&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-mr&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td class=&quot;x-btn-bl&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-bc&quot;&gt;&lt;/td&gt;
       &lt;td class=&quot;x-btn-br&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/td&gt;
      &lt;/tr&gt;
     &lt;/tbody&gt;
    &lt;/table&gt;
  </code></pre>
  <ol>
  <li>I need to click on 'Import Expenses' button which is part of 'x-btn-text menu_import2' class. I can not use XPATH or ID here, because it's dynamic value for different submission forms it has different values.
  So I try to use class: ''' driver.find_element_by_class_name(&quot; x-btn-text menu_import2&quot;) '''
  However, it gives me back an error:</li>
  </ol>
  <p><em>Traceback (most recent call last):
  File &quot;&lt;pyshell#23&gt;&quot;, line 1, in 
  driver.find_element_by_class_name(&quot; x-btn-text menu_import2&quot;)
  File &quot;C:\Users\ataranov\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py&quot;, line 564, in find_element_by_class_name
  return self.find_element(by=By.CLASS_NAME, value=name)
  File &quot;C:\Users\ataranov\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py&quot;, line 976, in find_element
  return self.execute(Command.FIND_ELEMENT, {
  File &quot;C:\Users\ataranov\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py&quot;, line 321, in execute
  self.error_handler.check_response(response)
  File &quot;C:\Users\ataranov\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py&quot;, line 242, in check_response
  raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
  (Session info: chrome=89.0.4389.90</em></p>
  <ol start="2">
  <li>At the same time I can find'x-toolbar-cell' class :'''driver.find_element_by_class_name(&quot;x-toolbar-cell&quot;)''' without any problems.</li>
  </ol>
  <ul>
  <li>What is the problem here to find class I need with '''find_element_by_class'''? Why it works for one class, but does not for another one?</li>
  <li>Is it somehow related to the fact that '''x-btn-text menu_import2 ''' is enclosed to other class? If so, how find class what are wrapped to other's classes?</li>
  <li>Any other way to find object in this case, like using button text title 'Import Expenses'</li>
  </ul>