title: Executing a Selenium command stored in a variable (Python > Webdriver)
body: <p>I'm trying to create a definition that allows me to click on an object regardless of the element type.  To achieve this, I created a variable containing the command I want to run.</p>
  
  <pre><code>def clickOnStaleElement(driver, objStrategy, element):
      lhs, rhs = objStrategy.split(".", 1)
      myCommand = "driver.find_element_by_"+rhs.lower()+"(\""+element+"\").click()"
  </code></pre>
  
  <p>I can't seem to figure out how to execute this command that's stored in the variable.  I tried '<strong>driver.execute_script()</strong>' but received a WebDriverException.  Trying '<strong>exec()</strong>', &amp; '<strong>eval()</strong>' resulted in the text hanging.  How do I achieve this?  Is there a better way to go about achieving this behavior?  I realize how I'm trying to achieve this behavior may not be ideal, so I'm open to better ways to accomplish the same task.  I'd prefer not to create 'if/then' statements for each element type, if possible.</p>