title: Webdriver - Locate Input via Label (Python)
body: <p>How do I locate an input field via its label using webdriver?</p>
  
  <p>I like to test a certain web form which unfortunately uses dynamically generated
  ids, so they're unsuitable as identifiers.</p>
  
  <p>Yet, the labels associated with each web element strike me as suitable. 
  Unfortunately I was not able to do it with the few suggestions
  offered on the web. There is one thread here at SO, but which did not
  yield an accepted answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/23704518/selenium-webdriver-java-clicking-on-element-by-label-not-working-on-certain-la">Selenium WebDriver Java - Clicking on element by label not working on certain labels</a></p>
  
  <p>To solve this problem in Java, it is commonly suggested to locate the label as an anchor via its text content and then specifying the xpath to the input element:</p>
  
  <pre><code>//label[contains(text(), 'TEXT_TO_FIND')]
  </code></pre>
  
  <p>I am not sure how to do this in python though.
  My web element:</p>
  
  <pre><code>&lt;div class="InputText"&gt;
      &lt;label for="INPUT"&gt;
          &lt;span&gt;
              LABEL TEXT
          &lt;/span&gt;
          &lt;span id="idd" class="Required" title="required"&gt;
              *
          &lt;/span&gt;
      &lt;/label&gt;
      &lt;span class="Text"&gt;
         &lt;input id="INPUT" class="Text ColouredFocus" type="text" onchange="var wcall=wicketAjaxPost(';jsessionid= ... ;" maxlength="30" name="z1013400259" value=""&gt;&lt;/input&gt;
     &lt;/span&gt;
     &lt;div class="RequiredLabel"&gt; … &lt;/div&gt;
     &lt;span&gt; … &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>