title: Wrapping Selenium "Expected Conditions" Python
body: <p>I am trying to create my own Selenium class with custom functions so that test scripting will become a bit more intuitive and more robust in some scenarios, for my taste at least. One of my current tasks is to wrap all Selenium expected conditions (described <a href="http://selenium-python.readthedocs.org/en/latest/api.html#module-selenium.webdriver.support.expected_conditions" rel="nofollow">here</a>) so that eventually I will have a single function that looks something like that:</p>
  
  <pre><code>def waitForElement(self, elementName, expectedCondition, searchBy)
  </code></pre>
  
  <p>Where:</p>
  
  <p><code>elementName</code> - the name of the element I am looking for. That could be id, name, xpath, css, etc...</p>
  
  <p><code>expectedCondition</code> - this is where the Selenium expected condition is set. So that can be: element_to_be_clickable, visibility_of_element_located, etc...</p>
  
  <p>The above function internally implements the standard Selenium <code>WebDriverWait</code> as follows:</p>
  
  <pre><code>try:
      if expectedCondition == "element_to_be_clickable":
          element = WebDriverWait(self.driver, defaultWait).until(EC.element_to_be_clickable((searchBy, elementName)))
      elif expectedCondition == "visibility_of_element_located":
          element = WebDriverWait(self.driver, defaultWait).until(EC.visibility_of_element_located((searchBy, elementName)))
  </code></pre>
  
  <p>All is good but I have a bit of trouble with passing the <code>searchBy</code> as a parameter. To remind, <code>searchBy</code> can be one of the following:</p>
  
  <pre><code>By.ID
  By.NAME
  By.CLASS_NAME
  ...
  </code></pre>
  
  <p>When I call this wrapper function from the main code, I do it with the below line:</p>
  
  <pre><code>self.waitForElement("elementName", "element_to_be_clickable", "By.NAME", "test")
  </code></pre>
  
  <p>So all parameters are passed as strings which is fine for everything except of the <code>searchBy</code> part.</p>
  
  <p>So my question is: <strong>How can I pass the <code>By.X</code> part as a parameter</strong> to my function?
  Hopefully I was able to describe my situation well. If I wasn't I will be happy to clarify.</p>